disp — Display values without returning output in MATLAB and RunMat.
disp prints a value to the command window/console without including the variable name. Supported value classes and formatting behavior follow MATLAB semantics.
Syntax
disp(X)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
X | Any | Yes | — | Value to display in the Command Window. |
Returns
| Name | Type | Description |
|---|---|---|
ans | NumericArray | Empty matrix placeholder returned by sink invocation. |
Errors
| Identifier | When | Message |
|---|---|---|
| — | Too many input arguments are passed to disp. | disp: too many input arguments |
| — | Input value cannot be gathered onto the host for rendering. | disp: failed to gather value for display |
How disp works
- Accepts exactly one input argument; additional arguments raise a MATLAB-compatible error.
- Numeric, logical, and complex arrays respect MATLAB’s column-major layout with right-aligned columns that honour the active numeric format.
- N-D arrays (with three or more dimensions) display one 2-D slice at a time with MATLAB-style
(:,:,[...]) =headers so each page mirrors the Command Window output. - Text inputs follow MATLAB conventions:
- Character arrays print each row as plain text without surrounding quotes.
- String scalars and arrays emit their contents (empty strings produce blank lines, missing strings render as
<missing>). - Structures display one field per line using four-space indentation; nested arrays collapse to size/type summaries just like MATLAB.
- Cell arrays print a compact grid using four-space indentation. Elements summarise their contents (e.g.,
[2x2 double],'hello',"world"). - gpuArray values are gathered to host memory before formatting so the output matches MATLAB.
- Empty arrays display as
[], while empty string arrays report their size (e.g.,0x2 string).
Does RunMat run disp on the GPU?
disp is a side-effecting sink. When the input (or nested values) reside on the GPU, RunMat gathers them to host memory using the active acceleration provider. Providers do not need to implement special hooks—the builtin always renders on the CPU before writing to standard output.
GPU memory and residency
disp is a side-effecting sink. When the input (or nested values) reside on the GPU, RunMat gathers them to host memory using the active acceleration provider. Providers do not need to implement special hooks—the builtin always renders on the CPU before writing to standard output.
Examples
Printing a message in the Command Window
disp("Simulation complete.")Expected output:
Simulation complete.Displaying numeric vectors with MATLAB spacing
angles = [0 pi/6 pi/4 pi/3];
disp(angles)Expected output:
0 0.5236 0.7854 1.0472Showing a matrix without variable names
A = [1 23 456; 78 9 10];
disp(A)Expected output:
1 23 456
78 9 10Printing struct fields in the Command Window
cfg = struct("solver", "bicgstab", "tolerance", 1e-8);
disp(cfg)Expected output:
solver: "bicgstab"
tolerance: 1e-08Displaying gpuArray data without manual gather
G = gpuArray([1 2; 3 4]);
disp(G); % RunMat gathers and prints host-formatted output automaticallyExpected output:
1 2
3 4Showing string and character arrays
names = ["alpha" "beta"; "gamma" "delta"];
disp(names);
disp('RunMat')Expected output:
"alpha" "beta"
"gamma" "delta"
RunMatUsing disp with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how disp changes the result.
Run a small disp example, explain the result, then change one input and compare the output.
FAQ
Does disp change the result of my computation?⌄
No. disp produces no output argument. Its return value is unused and exists only for internal compliance with the builtin registry.
Can I pass multiple arguments to disp?⌄
No. Like MATLAB, RunMat accepts exactly one input argument. Use fprintf or sprintf for formatted output with multiple values.
How are structs displayed?⌄
Each field appears on its own line with a four-space indent, followed by the formatted value. Nested values collapse to MATLAB-style summaries (for example, [3x3 double]), so even large structures remain readable.
What happens with empty arrays?⌄
Numeric and logical empties print as []. Empty string arrays display their shape (e.g., 0x0 string) so you can distinguish them from scalar empty strings.
Can disp print GPU data directly?⌄
Yes. You do not need to call gather yourself. RunMat gathers GPU-resident values internally, prints the MATLAB-compatible representation, and leaves residency decisions to the auto-offload planner.
How are missing strings shown?⌄
Missing string scalars are rendered as <missing>, mirroring MATLAB output.
Does disp honour the current numeric format (e.g., format long)?⌄
Yes. disp reuses the same formatting primitives as the Command Window, so global format settings (format short, format long, etc.) apply automatically.
Does disp add a blank line after printing?⌄
It prints each line followed by a newline. Empty strings result in a blank line, consistent with MATLAB.
What if the input is a cell array?⌄
RunMat prints a compact cell view using four-space indentation and MATLAB-style summaries ([2x2 double], 'text', "string"). Nested cell arrays appear as [mxn cell].
How do I print without a trailing newline?⌄
Use fprintf instead. disp always terminates the output with a newline.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fullfile · genpath · getenv · ls · mkdir · movefile · path · pwd · rmdir · rmpath · run · savepath · setenv · tempdir · tempname · uigetfile · uiputfile
Tabular
csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · readmatrix · spreadsheetImportOptions · writecell · writematrix · xlsread
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite
Import
Json
Archive
Http
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how disp is executed, line by line, in Rust.
- View the source for disp in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.