mexEvalString (C and Fortran)

Execute MATLAB command in caller workspace

C Syntax

#include "mex.h"
int mexEvalString(const char *command);

Fortran Syntax

#include "fintrf.h"
integer*4 mexEvalString(command)
character*(*) command



String containing MATLAB® command to execute


0 if successful, and 1 if an error occurs.


Call mexEvalString to invoke a MATLAB command in the workspace of the caller.

mexEvalString and mexCallMATLAB both execute MATLAB commands. Use mexCallMATLAB for returning results (left side arguments) back to the MEX file. The mexEvalString function cannot return values to the MEX file.

All arguments that appear to the right of an equal sign in the command string must be current variables of the caller workspace.

Do not use MATLAB function names for variable names. Common variable names that conflict with function names include i, j, mode, char, size, or path. To determine whether a particular name is associated with a MATLAB function, use the which function. For more information, see Variable Names.

Error Handling

If command detects an error, MATLAB returns control to the MEX-file and mexEvalString returns 1. If you want to trap errors, use the mexEvalStringWithTrap function.


See the following examples in matlabroot/extern/examples/mex.

Was this topic helpful?