MATLAB Function Reference
  Go to function:
    Search    Help Desk 
eval    Examples   See Also

Execute a string containing a MATLAB expression

Syntax

Description

eval(expression) executes expression, a string containing any valid MATLAB expression. You can construct expression by concatenating substrings and variables inside square brackets:

[a1,a2,a3,...] = eval(expression) executes expression and returns the results in the specified output variables. Using the eval output argument list is recommended over including the output arguments in the expression string:

The above syntax avoids strict checking by the MATLAB parser and can produce untrapped errors and other unexpected behavior.

eval(expression,catch_expr) executes expression and, if an error is detected, executes the catch_expr string. If expression produces an error, the error string can be obtained with the lasterr function. This syntax is useful when expression is a string that must be constructed from substrings. If this is not the case, use the try...catch control flow statement in your code.

Examples

This example executes a simple MATLAB expression:

This for loop generates a sequence of 12 matrices named M1 through M12:

See Also

assignin, catch, evalin, feval, lasterr, try



[ Previous | Help Desk | Next ]