Execute MATLAB expression in specified workspace
[a1, a2, a3, ...] = evalin(ws,
a character vector or string scalar containing any valid MATLAB® expression
using variables in the workspace
have a value of
denote the MATLAB base workspace or the workspace of the caller
[a1, a2, a3, ...] = evalin(ws, executes
returns the results in the specified output variables. Using the
argument list is recommended over including the output arguments in
evalin(ws,'[a1, a2, a3, ...] = function(var)')
The above syntax avoids strict checking by the MATLAB parser and can produce untrapped errors and other unexpected behavior.
This example extracts the value of the variable
the MATLAB base workspace and captures the value in the local
v = evalin('base', 'var');
evalin cannot be used recursively to evaluate
an expression. For example, a sequence of the form
'evalin(''caller'', ''x'')') doesn't work.
The MATLAB base workspace is the workspace that is seen from the MATLAB command line (when not in the debugger). The caller workspace is the workspace of the function that called the currently running function. Note that the base and caller workspaces are equivalent in the context of a function that is invoked from the MATLAB command line.
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
construct a handle to a function that is defined in the caller.
If you use
evalin('caller', expression) in
the MATLAB debugger after having changed your local workspace
dbdown, MATLAB evaluates the expression
in the context of the function that is one level up in the stack from
your current workspace context.