islogical — Return true when a value is stored as MATLAB logical data (scalar or array).
tf = islogical(x) returns a logical scalar that is true when x is stored as MATLAB logical data (either a scalar logical or an N-D logical array). All other value kinds, including doubles, integers, characters, structs, and objects, return false.
How islogical works in RunMat
- Logical scalars (
true,false) returntrue. - Instances of
logicalarrays returntrue, regardless of dimensionality. - Numeric, complex, string, character, struct, cell, and object inputs return
false. gpuArrayvalues returntruewhen their residency metadata marks them as logical; the builtin never gathers device buffers just to answer the query unless metadata is absent.- The result is always a logical scalar.
How islogical runs on the GPU
When RunMat Accelerate is active, islogical first asks the registered acceleration provider for the logical_islogical hook. Providers that implement the hook respond using device metadata without copying data back to the CPU. If the hook is missing, RunMat consults its own residency metadata and only gathers device buffers as a last resort, ensuring that the builtin always succeeds while minimizing host↔device transfers.
GPU memory and residency
You typically do **not** need to call gpuArray manually. RunMat's auto-offload planner keeps logical masks resident on the GPU when downstream expressions benefit from device execution. Explicit gpuArray and gather calls remain available for compatibility with MATLAB code that manages residency explicitly.
Examples
Checking a logical scalar
flag = islogical(true)Expected output:
flag =
1Verifying a logical array constructed with logical
mask = logical([1 0 1 0]);
is_mask_logical = islogical(mask)Expected output:
is_mask_logical =
1Numeric arrays are not logical
values = [1 2 3];
is_logical = islogical(values)Expected output:
is_logical =
0Character arrays return false
chars = ['R' 'u' 'n'];
is_char_logical = islogical(chars)Expected output:
is_char_logical =
0gpuArray comparisons yield logical gpuArrays
G = gpuArray([1 2 3]);
mask = G > 1;
tf = islogical(mask)Expected output:
tf =
1Containers and structs are not logical
items = {true, 1};
person = struct("name", "Ada");
tf_cell = islogical(items);
tf_struct = islogical(person)Expected output:
tf_cell =
0
tf_struct =
0FAQ
Does islogical ever return an array?
No. The builtin always returns a logical scalar, even when the input is an array.
Does islogical convert numeric data to logical?
No. It only reports whether the storage is already logical. Use the logical builtin to convert numeric data explicitly.
How does islogical behave with gpuArray inputs?
If the provider exposes logical_islogical, the check happens entirely on the GPU. When the hook is absent, RunMat consults residency metadata and, if needed, gathers the value to host memory to inspect its storage kind.
Are character or string arrays considered logical?
No. Character vectors, string scalars, and string arrays are not logical values and therefore return false.
Do cell arrays or structs ever count as logical?
No. Containers such as cell arrays, structs, tables, and objects always return false.
Does a logical gpuArray gathered back to the host stay logical?
Yes. When residency metadata marks the handle as logical, gathering produces a host logical array, and islogical continues to report true.
Related functions to explore
These functions work well alongside islogical. Each page has runnable examples you can try in the browser.
isreal, isfinite, isnan, gpuArray, gather, isgpuarray, isinf, isnumeric
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how islogical works, line by line, in Rust.
- View islogical.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.