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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
N | Any | Yes | — | Numeric or logical scalar, vector, or matrix input. |
Returns
| Name | Type | Description |
|---|---|---|
chr | Any | Character array containing the rounded integer text. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:int2str:InvalidInput | Input value is not a supported numeric/logical scalar, vector, or matrix. | int2str: unsupported input type |
RunMat:int2str:InvalidOption | Arguments are malformed or too many were supplied. | int2str: invalid option arguments |
RunMat:int2str:InternalError | Internal 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
0x0character 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.
Related Strings functions
Core
blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmp · strcmpi · string · string.empty · strings · strlength · strncmp · strncmpi · strtok · unicode2native
Text Analytics
addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · doc2sequence · encode · extractFileText · extractHTMLText · fastTextWordEmbedding · findElement · getAttribute · htmlTree · ind2word · isVocabularyWord · normalizeWords · readWordEmbedding · removeLongWords · removeShortWords · removeStopWords · removeWords · stopWords · tokenDetails · tokenizedDocument · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · wordEncoding · writeWordEmbedding
Transform
append · deblank · erase · eraseBetween · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strip · strjoin · strjust · strrep · strsplit · strtrim · upper
Search
contains · endsWith · matches · startsWith · strfind
Pattern
digitsPattern · lettersPattern · pattern · regexpPattern · textBoundary · wildcardPattern
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how int2str is executed, line by line, in Rust.
- View the source for int2str 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.