matlab与c c 混合编程 pdf,[转载]matlab与C的混合编程之入门

这里仅讲述matlab调用C的混合编程,暂不涉及C调用matlab的混合编程。

mtalab第一次调用C编程之前,需运行mex操作,此操作在windows系统下是一个bat的批处理文件,在unix系统下是个shell脚本。

>> mex

-setup //在matlab 的command window下运行此命令Please choose your

compiler for building external interface (MEX) files:

Would you like mex to locate installed compilers [y]/n?

y //是否调用本地安装好的c编译软件

Select a compiler:

[1] Lcc-win32 C 2.4.1 in C:PROGRA~1MATLABR2010bsyslcc

[2] Microsoft Visual C++ 6.0 in C:Program FilesMicrosoft Visual

Studio

[0] None

Compiler: 1 //也可以选择2 Please verify your choices:

Compiler: Lcc-win32 C 2.4.1

Location: C:PROGRA~1MATLABR2010bsyslcc

Are these correct [y]/n? y //确认正确 Trying to update options file:

C:UsersXJTAppDataRoamingMathWorksMATLABR2010bmexopts.bat

From

template: C:PROGRA~1MATLABR2010bbinwin32mexoptslccopts.bat

Done . . .

**************************************************************************

Warning: The MATLAB C and Fortran API has

changed to support MATLAB

variables with more than 2^32-1 elements. In the

near future

you will be required to update your code to utilize the new

API. You can find more information about this at:

http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9

Building with the -largeArrayDims option enables the new API.

**************************************************************************

>>

到此,matlab调用C的混合编程环境已经搭建好,下面举个简单例子:

#include

void mexFunction(int nlhs ,mxArray *plhs[] ,int nrhs, const mxArray

*prhs[])

{

mexPrintf("Hello word!");

}

把上面程序保存为一个C文件,如 hello.c

在command window下运行

>> mex hello.c

>>

结束之后在current folder 窗口里会有一个hello.mexw32文件。

在command window下运行

>> hello()

Hello word!

至此,一个简单的hello word程序已经完成。

在下一篇,会进行稍微深入的讲解如何编写C文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值