Skip to content

evalc

Evaluate a string and capture its console output.

result = evalc(expression)
[result, a1, a2, ...] = evalc(expression)

Executes expression and captures everything that would have been printed to the console as the string result. Side-effects on workspace variables still occur. Useful for testing functions whose primary effect is disp() / printf() output.

out = evalc('disp(magic(3))') % out captures the printed matrix
  • eval — Execute a string as MathJet code.
  • evalin — Evaluate a string in a different workspace.
  • sprintf — Format data into a string.