evalc — Evaluate source text in the current workspace and capture command-window output.

evalc evaluates source text in the current workspace and returns the text that would have appeared in the command window. Additional requested outputs receive values produced by the evaluated source.

Syntax

results = evalc(expression)
[results,varargout] = evalc(expression)

Inputs

NameTypeRequiredDefaultDescription
sourceStringScalarYesSource text to evaluate in the current workspace.

Returns

NameTypeDescription
resultsStringScalarCaptured Command Window text.
varargoutAnyValue(s) produced by evaluated source text.

Returned values from evalc depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:DynamicWorkspaceRequiresVmA dynamic workspace builtin is dispatched outside the VM workspace frame.dynamic workspace builtin requires VM workspace context

How evalc works

  • results = evalc(expression) evaluates expression in the current workspace and returns captured stdout/stderr command-window text as a string scalar.
  • [results,varargout] = evalc(expression) captures command-window text as the first output and forwards values produced by the evaluated source into later outputs.
  • The expression argument must be string-like source text accepted by the dynamic workspace evaluator.
  • Variables assigned by evaluated source are committed to the current workspace on success and are visible to subsequent requests or dynamic evaluations. Already-lowered later statements in the same request cannot statically bind newly introduced dynamic variables.
  • Command-window text produced during the evaluation is diverted into the returned string. It is not emitted to the normal execution stream and is not logged by diary.
  • Silent source text returns an empty string as the captured output.
  • Errors from evaluated source propagate to the caller. Partial workspace mutations are not committed when the dynamic evaluation fails.

Does RunMat run evalc on the GPU?

evalc is a host-side dynamic-workspace execution boundary. It does not create GPU kernels or participate in fusion. Evaluated code may still use GPU-capable builtins normally.

Examples

Capture display output from evaluated source

txt = evalc('disp(42)')

Expected output:

txt = "42\n"

Capture output while returning an evaluated value

[txt, value] = evalc('disp("gain"); 6 * 7')

Expected output:

txt = "gain\n"
value = 42

Persist assignments for later requests

txt = evalc('scale = 3; disp(scale)');
% A later request can read scale.

Expected output:

txt = "3\n"

Using evalc with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how evalc changes the result.

Run a small evalc example, explain the result, then change one input and compare the output.

FAQ

Does evalc print captured text to stdout?

No. Captured stdout and stderr text is returned as the first output instead of being forwarded to the normal command stream.

Does evalc write captured text to diary?

No. Diary logging is disabled inside the active capture scope, matching MATLAB's command-window capture behavior.

Where does evalc execute the source text?

RunMat executes the source in the current workspace through the VM dynamic-workspace path, the same ownership boundary used by eval.

Can later statements in the same request use variables newly created by evalc?

Not yet. The assignment is committed to the current workspace on success and is visible to later requests or dynamic evaluations, but already-lowered later statements in the same request cannot statically bind names introduced by dynamic source text.

Can evalc return values in addition to captured text?

Yes. When multiple outputs are requested, the first output is the captured string and later outputs receive values produced by the evaluated source.

Does evalc have a GPU fast path?

No. evalc is an execution and capture boundary. Code evaluated inside evalc can still call builtins that use acceleration, but evalc itself is not a numeric GPU operation.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how evalc is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.