How to return a matrix structure from a mex function?
问题 I have a struct that defines a 3d array, the size is known: struct uchar3 { unsigned char x, y, z; }; and I want to return it via mex function in order to use it in matlab like a three dimensional array, like an image. How can this be done? EDIT: This is apart of the function I use. foo(uchar3 **imagePtr, Mat Im){ unsigned char *cvPtr = Im.ptr<unsigned char>(0); for (size_t i = 0; i < Im.rows * Im.cols; ++i) { (*imagePtr)[i].x = cvPtr[3 * i + 0]; (*imagePtr)[i].y = cvPtr[3 * i + 1]; (