Skip to content

eval

Execute a string as MathJet code.

eval(str)
[a1, a2, ...] = eval(str)

Parses and evaluates str as MathJet code in the caller’s workspace. The string can contain any expression or statement. Variables created by eval persist in the caller’s scope.

Use sparingly: eval defeats compile-time checks and is a common source of subtle bugs. Most uses can be replaced with structures, function handles, or dynamic field access (s.(fieldname)).

eval('x = 1 + 2;') % x is now 3 in the caller
eval('sqrt(16)') % 4
  • evalin — Evaluate a string in a different workspace.
  • evalc — Evaluate a string and capture its console output.
  • assign — Assign a value to a variable by name.
  • feval