Code covered by the BSD License  

Highlights from
findfirst

from findfirst by Richard Hindmarsh
MEX file for finding first or last non-zero.

findfirst.m
% [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

%%%%%  Natural Environment Research Council, (2002)
%%%%% Written by R.C.A. Hindmarsh.

Contact us at files@mathworks.com