3.0

3.0 | 2 ratings Rate this file 0 Downloads (last 30 days) File Size: 1.38 KB File ID: #1472

Vectorized FIND

by Steven Lord

 

08 Mar 2002 (Updated 12 Mar 2002)

This function returns the locations of the elements of a vector in a matrix.

| Watch this File

File Information
Description

If A is a matrix and b is a column vector, this function returns a column vector of indices I such that A(I)==b if the elements of b are in A. If an element of b is not in A, then the corresponding element of I is Inf.

As an example, you can execute the following code:

rand('state',0)
A=floor(20*rand(5))
b=[18;8;9;6]
I=findin(A,b)
A(I(1:3))

The example above uses I(1:3) because I(4) is Inf; the matrix A does not have 6 as an entry.

MATLAB release MATLAB 6.0 (R12)
Other requirements This function has been tested in MATLAB 5.3 (R11) and MATLAB 6.0 (R12).
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
12 Mar 2002 u s

nicely implements

J=ismember(b,A(find(ismember(A,b))))
% followed by
b(J)

04 Jul 2006 Ofek Shilon

the native -

>> [dmp,I]=ismember(b,A);

achieves identical results in ~1% of the time.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
matrices Steven Lord 22 Oct 2008 06:42:54
vectorized Steven Lord 22 Oct 2008 06:42:54
find Steven Lord 22 Oct 2008 06:42:54
location Steven Lord 22 Oct 2008 06:42:54
vector Steven Lord 22 Oct 2008 06:42:54
matrix manipulation Steven Lord 22 Oct 2008 06:42:54

Contact us at files@mathworks.com