eval - Evaluate MATLAB expression - MATLAB (original) (raw)

Evaluate MATLAB expression

Syntax

Description

eval([expression](#mw%5Fda6cc3d7-b0f6-46b1-9e81-f9c96e554611)) evaluates the MATLAB® code in expression.

Note

Security Considerations: When callingeval 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:

Performance Considerations: In most cases, using theeval 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 toeval.

example

[[output1,...,outputN](#mw%5F0ff7b211-7176-42fa-9742-aa4189ef105c)] = eval([expression](#mw%5Fda6cc3d7-b0f6-46b1-9e81-f9c96e554611)) returns the outputs from expression in the specified variables.

example

Examples

collapse all

Evaluate Expression

Use eval to evaluate and plot the expression magic(5).

Z = eval('magic(5)'); mesh(Z)

Mesh plot of Z.

Input Arguments

collapse all

expression — Expression to evaluate

character vector | string scalar

Expression to evaluate, specified as a character vector or string scalar.expression must be a valid MATLAB expression and must not include any MATLAB keywords. To determine whether a word is a MATLAB keyword, use the iskeyword function.

Example: eval('magic(5)')

Output Arguments

collapse all

output1,...,outputN — Outputs from evaluated expression

any MATLAB data type

Outputs from evaluated expression, returned as any MATLAB data type.

Limitations

Tips

Extended Capabilities

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced before R2006a