evalin
Evaluate MATLAB expression in specified workspace
Description
evalin(
evaluates the MATLAB® code represented by workspace
,expression
)expression
using the
variables in the specified workspace.
Note
Security Considerations: When calling
evalin
with untrusted user input, validate the input to avoid
unexpected code execution. Examples of untrusted user input are data coming from a user you
might not know or from a source you have no control over. If you need to address this
concern, consider these approaches:
Validate inputs to
evalin
. First, search for allowed operations. Then, if you find other operations, disallow execution.Replace
evalin
with an alternative. For more information, see Alternatives to the eval Function.
Performance Considerations: In most cases, using the
evalin
function is also less efficient than using other
MATLAB functions and language constructs, and the resulting code can be more
difficult to read and debug. Consider using an alternative to
evalin
.
[
returns the outputs from output1,...,outputN
] = evalin(workspace
,expression
)expression
in the specified variables.
In order for this syntax to be valid the expression,
, must also be valid.output1,...,outputN
=
expression
Examples
Input Arguments
Output Arguments
Limitations
evalin('caller',expression)
finds only variables in the caller's workspace; it does not find functions in the caller. For this reason, you cannot useevalin
to construct a handle to a function that is defined in the caller.evalin
should not be used recursively to evaluate an expression and doing so may result in unexpected behavior.If you use
evalin
within an anonymous function, nested function, or function that contains a nested function, the evaluatedexpression
does not create any variables.
Tips
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 statementevalin('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)
Version History
Introduced before R2006a