View all functions

CategoryIo
GPUYes

What does the disp function do in MATLAB / RunMat?

disp prints the contents of a variable to the Command Window without including the variable name. RunMat mirrors MATLAB behaviour for numeric, logical, string, character, struct, cell, and gpuArray inputs so scripts and diagnostic utilities behave identically.

How does the disp function behave in MATLAB / RunMat?

  • 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).

GPU execution 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 of using the disp function in MATLAB / RunMat

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.0472

Showing a matrix without variable names

A = [1 23 456; 78 9 10];
disp(A);

Expected output:

     1    23   456
    78     9    10

Printing struct fields in the Command Window

cfg = struct("solver", "bicgstab", "tolerance", 1e-8);
disp(cfg);

Expected output:

    solver: "bicgstab"
  tolerance: 1e-08

Displaying gpuArray data without manual gather

G = gpuArray([1 2; 3 4]);
disp(G);             % RunMat gathers and prints host-formatted output automatically

Expected output:

     1     2
     3     4

Showing string and character arrays

names = ["alpha" "beta"; "gamma" "delta"];
disp(names);
disp('RunMat');

Expected output:

"alpha"    "beta"
"gamma"    "delta"
RunMat

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.

See Also

fprintf, sprintf, string, gather