且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在MEX函数中读取整数数组

更新时间:2023-01-14 11:23:03

看一下演示MEX函数explorer.c,您可以使用MATLAB在pEX中打开它

Take a look at the demo MEX-function explore.c, which you can open in MATLAB using

edit([matlabroot '/extern/examples/mex/explore.c']);

在这里您会发现一堆函数,它们的名称都以analyze_开头,然后是类型(例如,analyze_uint8).在这些函数中,您将看到对mxGetData的调用的输出被强制转换为特定的C类型,如下所示:

In there you'll find a bunch of functions whose names all start with analyze_ and then a type (for example, analyze_uint8). In those functions you'll see the output of calls to mxGetData being cast to a particular C type, like this:

pr = (unsigned char *)mxGetData(array_ptr);

pr现在指向array_ptr的实部,即unsigned char的数组.

pr now points to the real part of array_ptr, an array of unsigned char.