isstring — Test whether values are string arrays in MATLAB and RunMat.
tf = isstring(x) returns true when x is a string array (including string scalars) and false otherwise. Distinction from char and other types follows MATLAB semantics.
Syntax
tf = isstring(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Value inspected from metadata without payload conversion.
Returns
tf- Type
LogicalArray- Description
- Scalar logical type-query result.
Behavior
String scalars such as "RunMat" and string arrays like ["alpha", "beta"] both return logical(1).
Empty string arrays produced by strings(0) or string.empty(...) are still recognised as the string type, so they return logical(1).
Character arrays created with single quotes ('text'), cell arrays of character vectors, numeric tensors, logical masks, structs, tables, and other non-string containers return logical(0).
gpuArray inputs currently store numeric or logical tensors in RunMat, so isstring(gpuArray(...)) returns logical(0), matching MATLAB’s behaviour.
The result is always a host logical scalar, making it easy to use for argument validation, control-flow guards, or input parsing.
GPU and residency
isstring runs entirely from metadata. When you pass a gpuArray, RunMat inspects the handle and returns logical(0) because device buffers do not yet store string data. No kernels are launched, and no host↔device transfers occur, so the device allocation remains resident for subsequent operations.
You usually do NOT need to call gpuArray yourself in RunMat (unlike MATLAB).
In RunMat, the fusion planner keeps residency on GPU in branches of fused expressions. As such, calling isstring on a gpuArray result leaves the device allocation untouched while still answering the question using metadata only.
To preserve backwards compatibility with MathWorks MATLAB, and for when you want to explicitly bootstrap GPU residency, you can call gpuArray explicitly to move data to the GPU if you want to be explicit about the residency.
Since MathWorks MATLAB does not have a fusion planner, and they kept their parallel execution toolbox separate from the core language, as their toolbox is a separate commercial product, MathWorks MATLAB users need to call gpuArray to move data to the GPU manually whereas RunMat users can rely on the fusion planner to keep data on the GPU automatically.
Inspects metadata on the host; gpuArray inputs are classified without kernel launches.
Legacy examples and displayed results
Checking if a string scalar is recognised
tf = isstring("RunMat")
Expected display: tf = logical(1)
Detecting string arrays with multiple elements
values = ["alpha", "beta", "gamma"];
tf = isstring(values)
Expected display: tf = logical(1)
Distinguishing strings from character vectors
tf_string = isstring("hello");
tf_char = isstring('hello')
Expected display: tf_string = logical(1)
tf_char = logical(0)
Confirming that empty string arrays are still strings
emptyStrs = strings(0, 2);
tf = isstring(emptyStrs)
Expected display: tf = logical(1)
Recognising that numeric and logical arrays are not strings
numbers = [1 2 3];
mask = true(1, 3);
tf_numbers = isstring(numbers);
tf_mask = isstring(mask)
Expected display: tf_numbers = logical(0)
tf_mask = logical(0)
Validating cell arrays of character vectors
cells = {'a', 'b', 'c'};
tf = isstring(cells)
Expected display: tf = logical(0)
Inspecting gpuArray inputs without transfers
G = gpuArray(ones(2, 2));
tf = isstring(G)
Expected display: tf = logical(0)
Using isstring in argument validation
function greet(name)
if ~isstring(name)
error("Name must be provided as a string.");
end
disp("Hello " + name + "!");
end
greet("RunMat");
% greet(42); % throws "Name must be provided as a string."
Expected display: Hello RunMat!
Example
Inspect a type with an assertion
tf = isstring("RunMat")Using isstring with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isstring changes the result.
Run a small isstring example, explain the result, then change one input and compare the output.
FAQ
Does isstring return true for empty string arrays?⌄
Yes. Empty string arrays are still of type string, so isstring(strings(0)) returns logical(1).
How is isstring different from ischar?⌄
isstring recognises MATLAB’s modern string type introduced in R2016b. ischar recognises legacy character arrays created with single quotes. Only isstring returns true for double-quoted values.
What about string arrays stored inside cell arrays?⌄
Cell arrays are containers, so isstring({'a', 'b'}) returns logical(0). Use iscellstr or all(isstring(cells)) to validate the contents instead.
Can gpuArray hold string data in RunMat?⌄
Not currently. gpuArray values hold numeric or logical tensors, so isstring always reports logical(0) for device-resident data.
Does isstring inspect array contents element by element?⌄
No. It only checks the value’s type metadata, so the cost is constant regardless of array size.
Related Introspection functions
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · findprop · func2str · functions · get.p · getcallinfo · getmethod · inputname · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isUnderlyingType · isvalid · keyboard · loadobj · localfunctions · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mfilename · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · new_object · notify · numArgumentsFromSubscript · onCleanup · parse · saveobj · set.p · stats · str2func · subsasgn · subsref · superclasses · underlyingType · verLessThan · version · which · who · whos
Source you can read
Every RunMat function's source is public. Read exactly how isstring is executed, line by line, in Rust.
- View the source for isstring 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.