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
    • find
    • ind2sub
    • sub2ind

find — Locate nonzero indices and selected values in column-major order.

find returns one-based double indices of nonzero elements. With three outputs it also returns selected values in their original class, including exact wide integers.

Syntax

idx = find(X)
idx = find(X, K)
idx = find(X, direction)
idx = find(X, K, direction)
[row, col] = find(X)
[row, col] = find(X, K)
All supported find forms
idx = find(X)
idx = find(X, K)
idx = find(X, direction)
idx = find(X, K, direction)
[row, col] = find(X)
[row, col] = find(X, K)
[row, col] = find(X, direction)
[row, col] = find(X, K, direction)
[row, col, v] = find(X)
[row, col, v] = find(X, K)
[row, col, v] = find(X, direction)
[row, col, v] = find(X, K, direction)

Inputs

X
Type
Any
Required
Yes
Description
Input array to search.
K
Type
NumericScalar
Required
Yes
Description
Maximum number of indices to return.
direction
Type
StringScalar
Required
Yes
Description
RunMat-only direction selector: first or last.
direction
Type
StringScalar
Required
Yes
Default
"first"
Description
Direction selector: `"first"` or `"last"`.
NameTypeRequiredDefaultDescription
XAnyYes—Input array to search.
KNumericScalarYes—Maximum number of indices to return.
directionStringScalarYes—RunMat-only direction selector: first or last.
directionStringScalarYes"first"Direction selector: `"first"` or `"last"`.

Returns

idx
Type
NumericArray
Description
Linear indices of non-zero elements.
row
Type
NumericArray
Description
Row subscripts of non-zero elements.
col
Type
NumericArray
Description
Column subscripts of non-zero elements.
v
Type
Any
Description
Values at the reported row/column locations.
NameTypeDescription
idxNumericArrayLinear indices of non-zero elements.
rowNumericArrayRow subscripts of non-zero elements.
colNumericArrayColumn subscripts of non-zero elements.
vAnyValues at the reported row/column locations.

Returned values from find depend on how many outputs the caller requests.

Errors

RunMat:find:InvalidInput
When
Input type or option arguments are not valid for find.
Message
find: invalid input arguments
RunMat:find:ProviderOutput
When
GPU provider does not return expected output buffers for requested nargout.
Message
find: provider output buffer mismatch
RunMat:find:ProviderError
When
The owning provider fails to transfer or produce an admitted find result.
Message
find: provider execution failed
RunMat:find:InternalError
When
Internal tensor conversion/materialization fails while building outputs.
Message
find: internal error
IdentifierWhenMessage
RunMat:find:InvalidInputInput type or option arguments are not valid for find.find: invalid input arguments
RunMat:find:ProviderOutputGPU provider does not return expected output buffers for requested nargout.find: provider output buffer mismatch
RunMat:find:ProviderErrorThe owning provider fails to transfer or produce an admitted find result.find: provider execution failed
RunMat:find:InternalErrorInternal tensor conversion/materialization fails while building outputs.find: internal error

Selection and output shape

The optional positive integer K limits the matches. 'first' scans from the start; 'last' selects the final K matches but reports them in ascending order. A row-vector input gives row-oriented one-output indices; other inputs give a column. Two or three outputs are column vectors, with trailing N-D dimensions folded into the column subscript.

A zero scalar or empty matrix produces the empty matrix convention. Other empty row vectors retain row orientation. NaN and infinity count as nonzero; either nonzero complex component counts.

Compatibility and exactness

find(X,direction) is a RunMat-only convenience form; compatible direction selection supplies K. Typed-integer sparse values are likewise gated. All eight integer classes use authoritative storage for zero testing and the third value output.

Indices are doubles and reject values outside their exact range. The third output retains logical, single, complex, or integer storage as appropriate.

Resident execution

A capable binary64 provider can run find directly. Other resident inputs use owner-aware exact gathering and return each output to the same owner when the class can be represented. find is eager and is not fused.

Examples

Compile selection outputs and errors

A = [0 4 0; 7 0 9]; k = find(A); [r,c,v] = find(A); tail = find([1 0 2 3 0],2,'last'); direction = 'sideways'; caught = false; try; bad = find(A,1,direction); catch failure; caught = strcmp(failure.identifier,'RunMat:find:InvalidInput'); end

Reject an unknown direction

find([1 0], 1, 'sideways')

Find matrix positions

A = [0 4 0; 7 0 9];
k = find(A)

Expected output:

k = [2; 3; 6]

Select the final matches

A = [1 0 2 3 0];
k = find(A,2,'last')

Expected output:

k = [3 4]

Preserve wide integer values

A = uint64([0 0x0020000000000001u64]);
[r,c,v] = find(A)

Expected output:

r = 1, c = 2

Using find with coding agents

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

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

FAQ

What counts as nonzero?⌄

Exact nonzero values, NaN, and infinities; either component of a complex value can make it nonzero.

Does the value output preserve integer precision?⌄

Yes. It reads and returns authoritative integer storage without a double round trip.

Related Array functions

Indexing

ind2sub · sub2ind

Accumulation

accumarray

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat

Creation

colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · meshgrid · nan · ndgrid · nonzeros · ones · peaks · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros

Combinatorics

combinations · nchoosek · perms

Binning

discretize

Grouping

findgroups · groupcounts · grp2idx · splitapply

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size · width

Source you can read

Every RunMat function's source is public. Read exactly how find is executed, line by line, in Rust.

  • View the source for find 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.

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
  • Selection and output shape
  • Compatibility and exactness
  • Resident execution
  • Examples
  • Compile selection outputs and errors
  • Reject an unknown direction
  • Find matrix positions
  • Select the final matches
  • Preserve wide integer values
  • Using find with coding agents
  • FAQ
  • Related Array functions
  • Indexing
  • Accumulation
  • Sorting Sets
  • Shape
  • Creation
  • Combinatorics
  • Binning
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat