findfirst
Version 1.1.0.0 (2.33 KB) by
Richard Hindmarsh
MEX file for finding first or last non-zero.
[VALUE,INDEX] = FINDFIRST(A,SEARCHDIR)
Returns the value and optionally index of the first non-zero in A.
A must be full and double
If SEARCHDIR = 'first' (default) the search is from the first index
If SEARCHDIR = 'last', the search is backwards from the last index
This is a cmex file, and is an order of magnitude faster than using FIND, and two orders of magnitude faster than using MATLAB loops.
Tested on Windows NT/2000 VC 6.0, Linux (gcc 2.95) and Solaris (courtesy A Pearson)
Cite As
Richard Hindmarsh (2026). findfirst (https://uk.mathworks.com/matlabcentral/fileexchange/2631-findfirst), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R13
Compatible with any release
Platform Compatibility
Windows macOS LinuxCategories
Find more on MATLAB Compiler in Help Center and MATLAB Answers
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
