RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.2, Nov 26, 2026 ·

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • logical

logical — Convert values to logical type in MATLAB and RunMat.

logical(X) converts supported real numeric and character inputs into logical values. Zero maps to false and nonzero maps to true. NaN and complex numeric inputs are rejected. When RunMat extensions are enabled, string arrays and symbolic numeric constants are additionally accepted.

Syntax

tf = logical(A)

Inputs

A
Type
Any
Required
Yes
Description
Input value to convert.
NameTypeRequiredDefaultDescription
AAnyYes—Input value to convert.

Returns

tf
Type
LogicalArray
Description
Logical-converted result.
NameTypeDescription
tfLogicalArrayLogical-converted result.

Errors

RunMat:logical:TooManyOutputs
When
More than one output is requested.
Message
logical: too many output arguments
RunMat:logical:TooManyInputs
When
More than one input argument is provided.
Message
logical: too many input arguments
RunMat:logical:ConversionNotPossible
When
Input type cannot be converted to logical.
Message
logical: conversion to logical is not possible for this input type
IdentifierWhenMessage
RunMat:logical:TooManyOutputsMore than one output is requested.logical: too many output arguments
RunMat:logical:TooManyInputsMore than one input argument is provided.logical: too many input arguments
RunMat:logical:ConversionNotPossibleInput type cannot be converted to logical.logical: conversion to logical is not possible for this input type
RunMat:logical:GpuGatherFailedGPU input gather fails during host fallback.logical: failed to gather gpuArray input
RunMat:logical:InternalErrorInternal logical buffer materialization fails.logical: internal conversion error

Behavior

logical accepts scalars, dense arrays, N-D tensors, and gpuArrays. Shapes are preserved bit-for-bit.

Finite non-zero real numeric values and real infinities map to true; 0 and -0 map to false.

NaN and complex numeric inputs raise conversion errors rather than being coerced.

Character arrays are converted elementwise by interpreting code points (so 'A' becomes true, '\0' becomes false).

When RunMat extensions are enabled, string arrays convert elementwise by whether each element is nonempty; scalar strings remain unsupported.

Structs, cells, objects, and other unsupported types raise conversion errors.

Scalar results become logical scalars (true/false); dense higher-rank arrays produce dense logical arrays, and sparse inputs preserve sparse storage.

GPU behavior

When the acceleration provider supports the required hooks, RunMat creates a logical result on the input's exact GPU owner. If fallback is needed, automatically resident inputs may return a host logical value; explicitly resident inputs are restored to the originating owner or the operation fails rather than silently changing the residency contract.

When a GPU provider implements elem_ne and zeros_like, RunMat evaluates elem_ne(X, 0) into a new device result and marks that result as logical. The result is validated before use and does not alias the input.

If the provider cannot service the request, RunMat converts through the host. Automatically resident inputs may remain on the host; explicit gpuArray inputs are re-uploaded to the same owner or return an error.

Handles that are already flagged as logical (gpuArray.logical) are returned without modification.

Scalars remain scalars: converting a gpuArray scalar preserves the residency and returns a logical gpuArray scalar.

Prefers a device-side elem_ne(X, 0) cast when the provider supports elem_ne and zeros_like. Provider results are validated for exact owner, shape, storage kind, and aliasing.

Fusion

Logical conversion remains a fusion boundary; no elementwise template is currently registered.

Integer and execution contract

All eight fixed-width integer classes convert without binary64 materialization. One input and at most one output are supported; discarded outputs still perform validation. NaN, complex, and unsupported inputs raise RunMat:logical:ConversionNotPossible. String arrays and symbolic constants require their RunMat extension gates.

Execution uses a portable asynchronous runtime binding with no workspace, filesystem, UI, callback, or random-service access. Distributed inputs are materialized by the shared argument boundary; foreign values are rejected. Provider allocation, synchronization, transfer, and fallback costs remain owned by the shared placement layer.

Examples

Creating a logical mask from numeric data

values = [0 2 -3 0];
mask = logical(values)

Expected output:

mask =
  1×4 logical array
     0     1     1     0

Building a logical mask from a matrix

M = [-4 0 8; 0 1 0];
mask = logical(M)

Expected output:

mask =
  2×3 logical array
     1     0     1
     0     1     0

Treating real infinities as true

flags = logical([-Inf Inf 0])

Expected output:

flags =
  1×3 logical array
     1     1     0

Rejecting complex numeric conversion

logical(3 + 4i)

Expected output:

Error: conversion to logical from complex numeric data is not possible

Converting character arrays to logical values

chars = ['A' 0 'C'];
mask = logical(chars)

Expected output:

mask =
  1×3 logical array
     1     0     1

Keeping gpuArray inputs on the device

G = gpuArray([0 1 2]);
maskGPU = logical(G);
hostMask = gather(maskGPU)

Expected output:

hostMask =
  1×3 logical array
     0     1     1

Preserving empty shapes through logical conversion

emptyVec = zeros(0, 3);
logicalEmpty = logical(emptyVec)

Expected output:

logicalEmpty =
  0×3 logical array
     []

Using logical with coding agents

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

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

FAQ

Which input types does logical support?⌄

Real numeric, logical, character, sparse numeric, and supported gpuArray values are accepted. NaN and complex numeric values are rejected. Enabling RunMat extensions additionally accepts string arrays and symbolic numeric constants; structs, cells, objects, and function handles remain unsupported.

How are NaN or Inf values treated?⌄

Real positive and negative infinity evaluate to true. NaN is rejected with a conversion error.

How does logical handle complex numbers?⌄

Complex numeric inputs are rejected, including values whose imaginary component is zero.

Does the builtin change array shapes?⌄

No. Shapes are preserved exactly, including empty dimensions and higher-rank tensors.

What happens to existing logical arrays?⌄

They are returned verbatim. Logical gpuArrays remain on the device without triggering new allocations.

Can I convert strings with logical?⌄

Scalar strings are rejected. When RunMat extensions are enabled, string arrays are accepted as an extension: each nonempty element becomes true and each empty element becomes false.

What about structs, cells, or objects?⌄

They raise the same conversion error as MATLAB. Use functions like ~cellfun(@isempty, ...) to derive masks instead.

Does the GPU path allocate new buffers?⌄

Yes. The preferred device path computes elem_ne against a zero tensor into a distinct logical result. Fallback may create a host result, and explicit residency may require a new upload to the original owner.

Where can I learn more?⌄

See the references below and the RunMat source for implementation details.

Related Logical functions

Tests

allfinite · iscell · iscellstr · isfinite · isgpuarray · isinf · islogical · isnan · isnumeric · isreal · issparse · isstruct

Bit

and · not · or · xor

Rel

eq · ge · gt · isequal · isequaln · le · lt · ne

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Behavior
  • GPU behavior
  • Fusion
  • Integer and execution contract
  • Examples
  • Creating a logical mask from numeric data
  • Building a logical mask from a matrix
  • Treating real infinities as true
  • Rejecting complex numeric conversion
  • Converting character arrays to logical values
  • Keeping gpuArray inputs on the device
  • Preserving empty shapes through logical conversion
  • Using logical with coding agents
  • FAQ
  • Related Logical functions
  • Tests
  • Bit
  • Rel
  • About RunMat