Evaluate MATLAB expression in specified workspace
evalin(
evaluates the MATLAB® code represented by workspace
,expression
)expression
using the
variables in the specified workspace.
Note
In most cases, using the evalin
function is less
efficient than using other MATLAB functions and language constructs, and the resulting code can
be more difficult to read and debug. For more information, see Alternatives to the eval Function.
[
returns the outputs from output1,...,outputN
] = evalin(workspace
,expression
)expression
in the specified
variables.
evalin('caller',expression)
finds only
variables in the caller's workspace; it does not find
functions in the caller. For this reason, you cannot
use evalin
to construct a handle to a function that is
defined in the caller.
evalin
cannot be used recursively to evaluate an
expression. For example, statement
evalin('caller','evalin(''caller'',''x'')')
is
invalid.
If you use evalin
within an anonymous function, nested
function, or function that contains a nested function, the evaluated
expression
does not create any variables.
To allow the MATLAB parser to perform stricter checks on your code and avoid untrapped
errors and other unexpected behaviors, do not include output arguments in the
input to the evalin
function. For example, the statement
evalin('base',['output = ',expression])
is not
recommended.
Instead, specify output arguments to the evalin
function
to store the results of the evaluated expression. For example:
output = evalin('base',expression)