MATLAB: Passing a structure pointer from C mex file to matlab

structure pointer c mex file

Hi,
I m trying to pass a pointer of a static structure from C mex to matlab, this pointer will be used by another C mex function. any help will be much appreciated thanks in advance

Best Answer

The usual hack is to encapsulate the pointer in a MATLAB uint64 variable. I.e., set the data area of a uint64 mxArray to the value of your pointer and pass that variable around. However, you need to be careful that the pointer is indeed valid to use in that other mex routine or it will cause a MATLAB crash.