int2str — Convert rounded integer values to a character array in MATLAB and RunMat.

int2str(N) treats N as a numeric or logical scalar, vector, or matrix, rounds floating-point values to integers, and returns a MATLAB char array.

Syntax

chr = int2str(N)

Inputs

NameTypeRequiredDefaultDescription
NAnyYesNumeric or logical scalar, vector, or matrix input.

Returns

NameTypeDescription
chrAnyCharacter array containing the rounded integer text.

Errors

IdentifierWhenMessage
RunMat:int2str:InvalidInputInput value is not a supported numeric/logical scalar, vector, or matrix.int2str: unsupported input type
RunMat:int2str:InvalidOptionArguments are malformed or too many were supplied.int2str: invalid option arguments
RunMat:int2str:InternalErrorInternal char-array assembly failed.int2str: internal error

How int2str works

  • Floating-point values are rounded before conversion.
  • Scalar and vector inputs return one text row; matrix inputs return one character row per numeric row.
  • Columns are padded with spaces so each textual column aligns across rows.
  • Logical and integer inputs are accepted and formatted as numeric 0/1 or integer values.
  • GPU tensors are gathered to host memory before formatting.
  • Empty inputs return a 0x0 character array.
  • Complex inputs, inputs with more than two dimensions, and non-numeric inputs raise descriptive errors.

Examples

Convert An Integer

chr = int2str(256)

Expected output:

chr =
    '256'

Round A Floating-Point Value

chr = int2str(3.14159)

Expected output:

chr =
    '3'

Format A Numeric Matrix

chr = int2str([5 10 20; 100 200 400])

Expected output:

chr =
    '  5   10   20'
    '100  200  400'

Convert GPU-Resident Data

G = gpuArray([10.2 20.8]);
chr = int2str(G)

Expected output:

chr =
    '10  21'

Using int2str with coding agents

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

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

FAQ

How is int2str different from num2str?

int2str rounds numeric values to integers first and has no precision or format-string arguments. Use num2str when you need decimal formatting or explicit printf-style control.

Does int2str return a modern string scalar?

No. MATLAB int2str returns a character array. Wrap the result with string(...) if you need a string scalar.

Does int2str run on the GPU?

No. GPU inputs are accepted, gathered to host memory, and formatted on the CPU, matching MATLAB's documented GPU-array limitation.

Does int2str support complex inputs?

No. RunMat rejects complex inputs for int2str because MATLAB documents the input as a numeric matrix of integer values and does not document complex formatting for this function.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how int2str 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.