Code covered by the BSD License  

Highlights from
FINDARRAY

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 1.72 KB File ID: #6018

FINDARRAY

by Mukhtar Ullah

 

08 Oct 2004 (Updated 16 Nov 2010)

Find one array within another.

| Watch this File

File Information
Description

FINDARRAY Find one array within another
  I = FINDARRAY(A,B,'first') for the array B returns an index array of
  the same size as B containing the smallest absolute index in A for each
  element of B which is a member of A and 0 if there is no such index.
  FINDARRAY(A,B) is the same as FINDARRAY(A,B,'first').
  
  I = FINDARRAY(A,B,'last') for the array B returns an index array of
  the same size as B containing the highest absolute index in A for each
  element of B which is a member of A and 0 if there is no such index.

  I = FINDARRAY(A,B,'all') returns a NDIMS(B)+1 dimensional array such
  that I(:,...,k) contains the k-th absolute index in A for each element
  of B, 0 otherwise.

See also find, ismember

 Example:

 >> findarray(pascal(3),magic(2),'all')

 ans(:,:,1) =
      1 6
      0 5
 ans(:,:,2) =
      2 8
      0 0
 ans(:,:,3) =
     3 0
     0 0
 ans(:,:,4) =
     4 0
     0 0
 ans(:,:,5) =
     7 0
     0 0

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File  
Everyone's Tags
array, find, matrix, vector
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
02 Nov 2004 Mukhtar Ullah

This function can replace FINDMEMBER that has been removed from the file exchange.

11 Oct 2004 urs Schwarz (us)

unfortunately, this solution is several times faster (JIT-acc) and - more importantly - doesn't use as much memory:

ixi=zeros(size(b));
ixa=zeros(size(b));
for i=1:length(a)
ia=strfind(a,a(i));
ib=strfind(b,a(i));
ixi(ib)=ia(1);
ixa(ib)=ia(end);
end

us

Updates
14 Oct 2004

Simplified

15 Oct 2004

Rewritten to exploit JIT Accelerator, as suggested by urs Schwarz.

18 Oct 2004

uses ismember to make things faster

13 Dec 2004

major update in functionality

13 Dec 2004

optimised for speed

16 Nov 2010

Replaced if-else with switch-case.

Contact us