马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
<P><FONT face="Times New Roman" size=3>比如有这个代码~:<br>#include <math.h><br>void timestwo(double y,double x)<br>{<br>y=2*x;<br>return;<br>}<br>是不是用MEX命令编译后会生成以下代码还是??<br>#include “mex.h”</FONT></P>
<P><FONT face="Times New Roman" size=3>void timestwo(double y[],double x[])</FONT></P>
<P><FONT face="Times New Roman" size=3>{ </FONT></P>
<P><FONT face="Times New Roman" size=3>y[0]=2.0*x[0]</FONT></P>
<P><FONT face="Times New Roman" size=3>}</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">void mexFunction(int nlhs</FONT>,<FONT face="Times New Roman">mxArray *plhs[]</FONT>,<FONT face="Times New Roman">int nrhs</FONT>,<FONT face="Times New Roman">const mxArray *prhs[])</FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>{</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">double *x</FONT>,<FONT face="Times New Roman">*y</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">int mrows</FONT>,<FONT face="Times New Roman">ncols</FONT>;</FONT></P>
<P><FONT face="Times New Roman" size=3>if(nrhs!=1)</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">{</FONT></FONT></P>
<P><FONT size=3><FONT face="Times New Roman">mexErrMsgTxt(</FONT>"<FONT face="Times New Roman">One input required.</FONT>"<FONT face="Times New Roman">)</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">}</FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>else if (nlhs>1)</FONT></P>
<P><FONT size=3><FONT face="Times New Roman"> mexErrMsgTxt(</FONT>"<FONT face="Times New Roman">Too many output argument</FONT>"<FONT face="Times New Roman">)</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">mrows=mxGetM(prhs[0])</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">ncols=mxGetN(prhs[0])</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman"> if(!mxIsDouble(prhs[0])||mxIsComplex(prhs[0])||!(mrows==1&&ncols==1))</FONT></FONT></P>
<P><FONT size=3><FONT face="Times New Roman">mexErrMsgTxt(</FONT>"<FONT face="Times New Roman">Input must be a noncomplex scalar double.</FONT>"<FONT face="Times New Roman">)</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">plhs[0]=mxCreateDoubleMatrix(mrows,ncols,mxREAL)</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">x=mxGetPr(prhs[0])</FONT>;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">y=mxGetPr(plhs[0])</FONT>;</FONT></P>
<P><FONT face="Times New Roman" size=3>timestwo(y,x)</FONT></P>
<P><FONT face="Times New Roman" size=3>}<br>还是应该在MATLAB里写上边的代码还是怎样?然后是不是写完后保存为后缀为.c的文件~再用MEX 编译后再在MATLAB 中调用?<br></FONT></P>
[此贴子已经被cdwxg于2006-6-1 13:24:58编辑过]
|