cellstr — Convert text arrays to a cell array of character vectors.
cellstr converts character rows or string elements into character vectors stored in a cell array.
Syntax
C = cellstr(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Character array, string array, or supported RunMat text value.
Returns
C- Type
Any- Description
- Cell array of character vectors.
Errors
RunMat:cellstr:TooManyOutputs- When
- More than one output is requested.
- Message
cellstr: too many output arguments
RunMat:cellstr:InvalidInput- When
- The input is not a supported text value.
- Message
cellstr: input must be text-compatible
RunMat:cellstr:InvalidContents- When
- A cell input contains something other than a character vector or string scalar.
- Message
cellstr: cell array elements must be text scalars
- When
- The supplied array shape does not match its storage.
- Message
cellstr: internal shape error
Character and string arrays
cellstr(A) converts each string element to a character vector and preserves the string array's shape. A character array instead produces one output cell per row and removes trailing whitespace from each row, except for significant whitespace such as a nonbreaking space.
An empty string scalar produces one cell containing an empty character array. An empty string array preserves its array shape, while a character array with zero rows produces a 0-by-1 cell array.
RunMat text inputs
RunMat compatibility mode also accepts cell arrays containing character vectors and string scalars, and symbolic scalars or arrays. Cell-array conversion preserves the outer shape and moves existing character vectors into the new container without inspecting resident numeric providers.
Cell and symbolic inputs are explicit RunMat extensions. MATLAB compatibility mode rejects those forms. Numeric, logical, object, and resident tensor inputs are not converted to text.
Current coverage
Character and string arrays are supported in native and browser runtimes. Datetime, duration, calendar-duration, and categorical forms are not yet implemented; the catalog marks the contract incomplete until those documented forms have implementations.
Typed missing string elements are rejected because this conversion requires character contents. Literal <missing> text converts as ordinary text; no broader missing-value compatibility claim is made.
Examples
Convert character-array rows
A = ['abc '; 'defg'; 'hi '];
C = cellstr(A);Expected output:
C is a 3-by-1 cell array containing 'abc', 'defg', and 'hi'Preserve a string array's shape
A = ["north", "south"; "east", "west"];
C = cellstr(A);Expected output:
C is a 2-by-2 cell array of character vectorsConvert an empty string scalar
C = cellstr("");Expected output:
C is a scalar cell containing an empty character arrayConvert one string scalar
C = cellstr("RunMat");Expected output:
C is a scalar cell containing 'RunMat'Convert an empty character array
A = char(zeros(0, 5));
C = cellstr(A);Expected output:
C is a 0-by-1 cell arrayNormalize an existing text cell array
C = cellstr({'left', "right"});Expected output:
C contains two character vectorsReject numeric input
cellstr(42);Expected output:
RunMat:cellstr:InvalidInputUsing cellstr with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how cellstr changes the result.
Run a small cellstr example, explain the result, then change one input and compare the output.
FAQ
Which whitespace is removed from character-array rows?⌄
Trailing whitespace is removed except for significant whitespace such as a nonbreaking space. Interior characters are unchanged; character vectors already stored in cell inputs are not trimmed.
Does conversion gather GPU data?⌄
No. RunMat has no resident text representation. Resident numeric values reject before provider lookup, including values nested in a cell input.
Why are cell and symbolic inputs marked as extensions?⌄
They are useful RunMat conversions but are not part of the documented compatible input set. They require RunMat compatibility mode.
Related Cells functions
Source you can read
Every RunMat function's source is public. Read exactly how cellstr is executed, line by line, in Rust.
- View the source for cellstr in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.