1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include "mex.h"
void
mexFunction (int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
char *str;
mxArray *v;
int found = 0;
if (nrhs != 2 || ! mxIsChar (prhs[0]))
mexErrMsgTxt ("Arguments must be a symbol name and a value");
str = mxArrayToString (prhs[0]);
// FIXME: If variable does not exist, error is reported which prevents
// subsequent mexGetArray function from working.
v = mexGetArray (str, "global");
if (v)
{
mexPrintf ("%s is a global variable with the following value:\n", str);
mexCallMATLAB (0, NULL, 1, &v, "disp");
found = 1;
}
if (! found)
v = mexGetArray (str, "caller");
if (! found && v)
{
mexPrintf ("%s is a caller variable with the following value:\n", str);
mexCallMATLAB (0, NULL, 1, &v, "disp");
}
// WARNING!! Can't do this in MATLAB! Must copy variable first.
mexPutVariable ("caller", str, prhs[1]);
}
|