coder.findOrError
Find indices and values of nonzero elements in an array in generated C/C++ code
Since R2026a
Syntax
Description
returns the first k = coder.findOrError(X,n)n linear indices corresponding to the nonzero
elements in the array X. If you only provide the X
argument, coder.findOrError uses the default value
1 for n.
If
Xis a vector, thenkis a vector with the same orientation asX.If
Xis a multidimensional array, thenkis a column vector.If
Xis a variable-size matrix at code generation time and a row vector at run time, then the output of the generated MEX function is a column vector, not a row vector.
In MATLAB® execution, if the array X contains fewer than
n nonzero elements, coder.findOrError has the
same behavior as find. For such inputs, code generation
produces either a compile-time or a run-time error.
Note
Unlike the find function that
always returns variable-length vectors in code
generation, the coder.findOrError function returns vectors of fixed
length n if the argument n is a constant during
code generation. If the array X contains fewer than
n nonzero elements, coder.findOrError produces
either a compile-time or a run-time error.
Examples
Input Arguments
Output Arguments
Extended Capabilities
Version History
Introduced in R2026a