Friday, April 19, 2019

Accessing workspace from C-Mex s-function

In Matlab Simulink you can access workspace variables from a C-Mex (C++/C) s-function as follows:



To write to workspace from C-Mex, you can use
#include "matrix.h"
...
mxArray* pa = mxCreateDoubleScalar(12.34);
mexPutVariable("base", "myVarName", pa);

Note that you cannot use myVarName in a simulink block unless you call it before or during InitFcn.

No comments: