Skip to content

assign

Assign a value to a variable by name.

v = assign(lhs, rhs)

Assigns rhs to the variable named lhs (a string) in the caller’s workspace. Equivalent to evaluating <lhs> = <rhs> via eval but avoids the parser overhead. Returns the assigned value.

assign('x', 42); % equivalent to: x = 42;
  • eval — Execute a string as MathJet code.
  • evalin — Evaluate a string in a different workspace.
  • deal — Distribute multiple inputs to multiple outputs.