Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1151641
  • 博文数量: 139
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 1712
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 23:10
个人简介

每天进步一点点。

文章分类

全部博文(139)

文章存档

2015年(3)

2014年(11)

2013年(25)

2011年(1)

2009年(3)

2008年(29)

2007年(45)

2006年(22)

分类: Windows平台

2014-07-28 23:37:54

博客成了单机版,基本上没有人看了。我就当给自己写总结吧。

把最近在做的事情简单记一个流水账吧。

最近在网易上mooc,学习python程序设计和高等数学。
python的教程其实看过两遍了,只是工作中一直用不到,所以学了就忘记了,这次学习主要是为了混个mooc的证书,呵呵 。
学习高等数学其实是为了提高一下自己的数学思维能力 ,然后希望在学习的过程中,可以结合自己的工作,能够从中有所收获或者启发 。
在学习高等数学的过程中,发现我现在基本上不用笔写字了,打算推导一下公式,发现找不到笔和纸了。
在这个过程找发现,发现一个数学软件Maxima,比较简单实用,可以用来做一些简单和常用的微积分计算。

最近还在看matlab coder这个模块的功能。
这个模块可以把*.m文件转换为C代码。不过从举的例子来看,一般是把某个写好的函数转换为C代码。转换过程一般为,首先转换为mex格式的,看看转换过程中是否有错误,然后运行转换之后的mex,看看是否有运行时错误。转换过程和运行都没有问题之后,就正式开始转。

以一个简单的函数为例子:
函数如下:

  1. function y = hello(x)
  2. y = sin(x);
  3. end
对这个函数进行转换时,需要指定 输入参数的数据类型。可以通过定义一个实例,通过这个实例的类型来指定。例如,可以定义如下变量:
 x = pi/2

然后通过如下命令来程序mex文件:
codegen hello -args {x}

生成成功之后,在文件夹当中会生成hello_mex.mexw32。这个就是mex文件。可以在matlab当中调用,来进行测试。例如:
y = hello_mex(x)


y =


     1


然后可以通过下面的命令来生成源代码 。
codegen -config coder.config('lib') hello -args {x}
生成的代码在codegen/lib/hello目录当中。里面有很多文件,但是我们需要的函数在hello.c和hello.h目录当中。代码如下:

  1. /*
  2.  * File: hello.c
  3.  *
  4.  * MATLAB Coder version : 2.6
  5.  * C/C++ source code generated on : 28-Jul-2014 23:30:59
  6.  */

  7. /* Include files */
  8. #include "rt_nonfinite.h"
  9. #include "hello.h"

  10. /* Function Definitions */

  11. /*
  12.  * Arguments : double x
  13.  * Return Type : double
  14.  */
  15. double hello(double x)
  16. {
  17.   return sin(x);
  18. }

  19. /*
  20.  * File trailer for hello.c
  21.  *
  22.  * [EOF]
  23.  */

  1. /*
  2.  * File: hello.h
  3.  *
  4.  * MATLAB Coder version : 2.6
  5.  * C/C++ source code generated on : 28-Jul-2014 23:30:59
  6.  */

  7. #ifndef __HELLO_H__
  8. #define __HELLO_H__

  9. /* Include files */
  10. #include <math.h>
  11. #include <stddef.h>
  12. #include <stdlib.h>
  13. #include "rtwtypes.h"
  14. #include "hello_types.h"

  15. /* Function Declarations */
  16. extern double hello(double x);

  17. #endif

  18. /*
  19.  * File trailer for hello.h
  20.  *
  21.  * [EOF]
  22.  */

如果修改传入参数的实例类型,则会生成不同的代码。例如,把输入的x修改为一组数据。
 x = 0:pi/1024:pi;
codegen -config coder.config('lib') hello -args {x}
则生成的代码如下:


  1. /*
  2.  * File: hello.c
  3.  *
  4.  * MATLAB Coder version : 2.6
  5.  * C/C++ source code generated on : 28-Jul-2014 23:35:15
  6.  */

  7. /* Include files */
  8. #include "rt_nonfinite.h"
  9. #include "hello.h"

  10. /* Function Definitions */

  11. /*
  12.  * Arguments : const double x[1025]
  13.  * double y[1025]
  14.  * Return Type : void
  15.  */
  16. void hello(const double x[1025], double y[1025])
  17. {
  18.   int i0;
  19.   for (i0 = 0; i0 < 1025; i0++) {
  20.     y[i0] = sin(x[i0]);
  21.   }
  22. }

  23. /*
  24.  * File trailer for hello.c
  25.  *
  26.  * [EOF]
  27.  */


  1. /*
  2.  * File: hello.h
  3.  *
  4.  * MATLAB Coder version : 2.6
  5.  * C/C++ source code generated on : 28-Jul-2014 23:35:15
  6.  */

  7. #ifndef __HELLO_H__
  8. #define __HELLO_H__

  9. /* Include files */
  10. #include <math.h>
  11. #include <stddef.h>
  12. #include <stdlib.h>
  13. #include "rtwtypes.h"
  14. #include "hello_types.h"

  15. /* Function Declarations */
  16. extern void hello(const double x[1025], double y[1025]);

  17. #endif

  18. /*
  19.  * File trailer for hello.h
  20.  *
  21.  * [EOF]
  22.  */

后续会多进行一些实践,掌握好这个工具。
阅读(2395) | 评论(0) | 转发(0) |
0

上一篇:libFaac--- FAAC的API

下一篇:书籍推荐

给主人留下些什么吧!~~