Mr. Nobody
Mr. Nobody

Reputation: 340

mex function fill mxCreateDoubleMatrix MATLAB

I have those lines of code:

cam::intStruct image = de->get_image ();
int i, j;
plhs[0] = mxCreateDoubleMatrix(320, 120, mxREAL);
memcpy(image.arr, plhs[0], 320 * 120 * sizeof(double));

and Im trying to fill plhs[0] with image content, but as result i get all 0 values in output (plhs[0]).

struct intStruct 
{
    int arr[320][120];
};

What am i doing wrong?

Upvotes: 0

Views: 818

Answers (1)

Rumman Khan
Rumman Khan

Reputation: 46

You are trying to fill plhs[0] with the image content. That means, plhs[0] is the destination and image arr is the source.

If this is the case then I think memcpy should be changed as follows.

first get a pointer to plhs[0],

double *ptr = (double *)mxGetData(plhs[0]);

then do the memcpy on this pointer.

memcpy(ptr, image.arr, 320 * 120 * sizeof(double));

Upvotes: 1

Related Questions