Mex files: how to return an already allocated matlab array

后端 未结 2 1417
庸人自扰
庸人自扰 2020-12-01 20:22

I have found a really tricky problem, which I can not seem to fix easily. In short, I would like to return from a mex file an array, which has been passed as mex function in

2条回答
  •  渐次进展
    2020-12-01 20:48

    You should use mxDuplicateArray, thats the documented way:

    #include "mex.h"
    
    void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
    {
        plhs[0] = mxDuplicateArray(prhs[0]);
    }
    

提交回复
热议问题