From: Kate J. on
Update: there is a very straightforward way to pass data between an m-file and a C-MEX s-function:

Within my gui’s m-file code, I use assignin(‘base’, varName, handles.VarName) and evalin(‘base’,’VarName’) calls to pass variables to and get variables from the Matlab workspace.

Within my C-MEX s-function code, I use calls to the mexGetVariable(“base”,”varName” ) and mexPutVariable(“base”,”varName”,varname_ptr) calls to get variables from and pass variables to the Matlab workspace.