eval
ExecuteMATLABexpression in text
Syntax
eval(expression)
[output1,...,outputN] = eval(expression)
Description
eval(
evaluates the MATLAB®code represented byexpression
)expression
. If you useeval
within an anonymous function, nested function, or function that contains a nested function, the evaluatedexpression
cannot create a variable.
[
stores output fromoutput1,...,outputN
] = eval(expression
)expression
in the specified variables.
Input Arguments
|
Character vector or string scalar that contains a valid MATLAB expression. To include a numeric value in the expression, convert it to a character vector or string scalar. |
Output Arguments
|
Outputs from the evaluated |
Examples
Tips
Many common uses of the
eval
function are less efficient and are more difficult to read and debug than other MATLAB functions and language constructs. For more information, see替代eval函数.Whenever possible, do not include output arguments within the input to the
eval
function, such aseval(['output = ',expression])
. The preferred syntax,output = eval(expression)
allows the MATLAB parser to perform stricter checks on your code, preventing untrapped errors and other unexpected behavior.