我目前正在编写一个MEX函数,它必须在MATLAB中使用单元数组 . MEX文件用C语言编写 .
本质上,我的函数的输入将是一个单元格数组,其中每个条目都是具有实数值的数字矩阵 . 一个简单的例子是:
C = cell(1,2);
C{1} = ones(10,10);
C{2} = zeros(10,4);
我希望能够访问我的MEX文件中的数字数组C {1}和C {2} . 理想情况下,我想这样做而不必在我的MEX文件中创建数据的第二个副本(即获取它们的指针) .
使用前面的示例,我目前的方法如下:
/* declare a pointer variable to the incoming cell array after it is passed to the MEX function */
mxArray C_CELL = (mxArray *) mxGetData(prhs[0])
/* declare a 2 x 1 array of pointers to access the cell array in C */
double *myarray[2] //
/* point towards the contents of C_CELL */
myarray[0] = mxGetPr(C_CELL[0])
myarray[1] = mxGetPr(C_CELL[1])
不幸的是,这似乎产生了“无效使用未定义类型'struct mxArray_tag'”错误 .