设为首页 加入收藏

TOP

Ubuntu 14.04下用GCC及gfortran编写MEX程序(Matlab2012a)(二)
2015-12-15 23:09:09 来源: 作者: 【 】 浏览:11
Tags:Ubuntu 14.04 下用 GCC gfortran 编写 MEX 程序 Matlab2012a
2);
? MyData(double v1 = 0, double v2 = 0);
? ~MyData() { }
private:
? double val1, val2;
};
?
MyData::MyData(double v1, double v2)
{
? val1 = v1;
? val2 = v2;
}
?
void MyData::display()
{
#ifdef _WIN32
? ? mexPrintf("Value1 = %g\n", val1);
? ? mexPrintf("Value2 = %g\n\n", val2);
#else
? cout << "Value1 = " << val1 << "\n";
? cout << "Value2 = " << val2 << "\n\n";
#endif
}
?
void MyData::set_data(double v1, double v2) { val1 = v1; val2 = v2; }
?
/*********************/
?
static
void mexcpp(
? ? ? ? double num1,
? ? ? ? double num2
? ? ? ? )
{
#ifdef _WIN32
? ? mexPrintf("\nThe initialized data in object:\n");
#else
? cout << "\nThe initialized data in object:\n";
#endif
? MyData *d = new MyData; // Create a? MyData object
? d->display();? ? ? ? ? // It should be initialized to
? ? ? ? ? ? ? ? ? ? ? ? ? // zeros
? d->set_data(num1,num2); // Set data members to incoming
? ? ? ? ? ? ? ? ? ? ? ? ? // values
#ifdef _WIN32
? mexPrintf("After setting the object's data to your input:\n");
#else
? cout << "After setting the object's data to your input:\n";
#endif
? d->display();? ? ? ? ? // Make sure the set_data() worked
? delete(d);
? flush(cout);
? return;
}
?
void mexFunction(
? ? ? ? int? ? ? ? ? nlhs,
? ? ? ? mxArray? ? ? *[],
? ? ? ? int? ? ? ? ? nrhs,
? ? ? ? const mxArray *prhs[]
? ? ? ? )
{
? double? ? ? *vin1, *vin2;
?
? /* Check for proper number of arguments */
?
? if (nrhs != 2) {
? ? mexErrMsgIdAndTxt("MATLAB:mexcpp:nargin",
? ? ? ? ? ? "MEXCPP requires two input arguments.");
? } else if (nlhs >= 1) {
? ? mexErrMsgIdAndTxt("MATLAB:mexcpp:nargout",
? ? ? ? ? ? "MEXCPP requires no output argument.");
? }
?
? vin1 = (double *) mxGetPr(prhs[0]);
? vin2 = (double *) mxGetPr(prhs[1]);
?
? mexcpp(*vin1, *vin2);
? return;
}
?


>> mex mexcpp.cpp


>> mexcpp(2,4)


The initialized data in object:


Value1 = 0


Value2 = 0



After setting the object's data to your input:


Value1 = 2


Value2 = 4


(3)gfortran


# include
?
? ? ? subroutine mexFunction ( nlhs, plhs, nrhs, prhs )
?
c*********************************************************************72
c
cc MEXFUNCTION is a MATLAB/F77 interface for the factorial function.
c
c? Discussion:
c
c? ? The MATLAB user types
c
c? ? integer plhs(*), prhs(*)
c? ? integer nlhs, nrhs
?
? ? ? integer nlhs
? ? ? integer nrhs
?
?
? ? ? mwpointer plhs(nlhs)
? ? ? mwpointer prhs(nrhs)
?
? ? ? call mexPrintf('Hello MATLAB World!')
?
? ? ? return
? ? ? end


>> mex mexHelloWorld.F


>> mexHelloWorld


Hello MATLAB World!>>


>>


?


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇iOS自定义的emoji表情键盘 下一篇C11标准的泛型机制

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: