我有一个DLP工具包,我需要通过MATLAB使用C++ API进行控制.
比如,我{load_data, load_settings,display_data}在一个名为dlp_controller.cpp/.c的mex文件中使用C/C++的函数/方法.
我知道我可以dlp_controller();用MATLAB 打电话.
有没有办法可以直接从MATLAB调用这个mex的方法?
说我的dlp_controller.cpp mex看起来像:
class dlp{ ... }
dlp::dlp{ ... }
dlp::load_data{ ... }
dlp::load_settings{ ... }
dlp::display_data{ ... }
void mexFunction(int nlhs, mxArray *[],int nrhs, const mxArray *prhs[]{ ... }
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式调用dlp_controller.load_dataMATLAB中的方法吗?注意:解决方法可以是dlp_controller使用该函数和传递的数据向内部发送变量并调用该函数.
我有一个Matlab的结构传递给mex.它正确传递,我用mxGetClassName(mxArray_pointer_carrying_struct)验证它,它返回struct作为类类型.该结构有15个字段n对应的属性,所有30个字符串(15个property_names,15个property_values).
我可以使用mxGetFieldNameByNumber(mxArray_pointer_carrying_struct,index)访问属性名称;
如何访问属性值?
我上面要做的代码如下所示:
extract_settings(const mxArray *p)
{
mwIndex j = 1;
const char *property;
mexPrintf("\nInput Arg %i is of type:%s\n",j,mxGetClassName(p));
for(int i = 0;i<=14;i++)
{
property = mxGetFieldNameByNumber(p, i); %gets property names
mexPrintf("%s-- \n",property); %Displays 15 property names
}
}
Run Code Online (Sandbox Code Playgroud)
我的结构如下所示:
{
TRIGGER_POLARITY : LEVEL_LOW
EDGE : EDGE_RISING
.
.
. (15 elements as of now)
}
Run Code Online (Sandbox Code Playgroud)