5.0

5.0 | 2 ratings Rate this file 5 Downloads (last 30 days) File Size: 5.13 KB File ID: #24641

Vectorized FIND with 'FIRST' option

by Bruno Luong

 

05 Jul 2009 (Updated 19 May 2010)

Find the first non-zero element(s) along row/column - or any other dimension

| Watch this File

File Information
Description

Up to now, to find the first non-zero element of a matrix along a column (for example) user might:

1. Use for-loop with FIND command
      for j=1:size(A,2)
            ... = find(A(:,j), 1, 'first');
      end
 
2. Use other vectorized methods, often time not very straight-forwards (MAX, LOGICAL, SPARSE, etc...). This method creates temporary arrays and scan such the arrays few times while doing some calculation.

3. Write the basic FOR-LOOP algorithm to accomplish the task.

The FINDFIRST command does just the same, but implemented using MEX engine which should be faster than any of the above. It can handle 'FIRST', 'LAST' option, and return more than one FIND count.

NOTE: not yet tested on Linux (gcc)

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Mex setup
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
17 Apr 2010 Gianni Schena

handy and fast ! it implemnts an option not available in the standard matlab find function

17 Apr 2010 Andrea Freddi  
Please login to add a comment or rating.
Updates
19 May 2010

Fix a bug when 'last' in invoked on 64-bit platform

Tag Activity for this File
Tag Applied By Date/Time
find Bruno Luong 06 Jul 2009 11:58:24
nonzeros Bruno Luong 06 Jul 2009 11:58:24

Contact us at files@mathworks.com