3.5

3.5 | 2 ratings Rate this file 85 downloads (last 30 days) File Size: 616 Bytes File ID: #6421

FINDROW

by Mukhtar Ullah

 

29 Nov 2004 (Updated 31 Aug 2005)

No BSD License  

Find indices of a given row within a matrix when INTERSECT can't help

Download Now | Watch this File

File Information
Description

FINDROW Find indices of a given row within a matrix.

  R = FINDROW(A, B) returns indices of the rows in A that coincide with
  row vector B , otherwise empty.
  [R, I] = FINDROW(A, B) also returns the indices of elements of rows R.

Note that the use of INTERSECT for the same purpose is limited because
the results are sorted and repeated entries are not taken care of.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
01 Dec 2004 Brett Shoelson

From your description, I would think that for A = magic(4); B = A(3,:); that k=findrow(A,B) would return 3. I'm puzzled by the need for that functionality ([i,k]=intersect(A,B,'rows') returns the same), and MORE puzzled by what it DOES return. Perhaps you can provide an example of its usefulness?

01 Dec 2004 Mukhtar Ullah

Thanks for your interest. You are right that my description is not clear, but I have updated it and will apear soon. In fact this function returns k such that A(k)=B (not A(k,:)=B); so in your example it will return k = [3 7 11 15]. The updated function will return two outputs! 3,[3 7 11 15]

01 Dec 2004 Mukhtar Ullah

The updated version will no longer require FINDARRAY.

02 Dec 2004 Brett Shoelson

So you are jumping through hoops to return j and sub2ind(size(A),A(i)) (Given: [i,j] = intersect(A,B,'rows');)
Why?

02 Dec 2004 Mukhtar Ullah

Perhaps you have not read propelly the new description. To get what i want to do: try this
a = pascal(5); b = a(3,:);
[i,j] = intersect(a,b,'rows');
sub2ind(size(a),a(i)) gives [1 1 1 5 15] which is nonsense while
[i,j] = findrow(a,b) gives

i = 3 and j = [3 8 13 18 23]. This j contains indices to 3rd row.

02 Dec 2004 Mukhtar Ullah

intersect function has two problems: it sorts the indices which distorts them; and it has no way of dealing with repeated elements.

05 Nov 2008 Betty  
05 Nov 2008 Jos

Unfortunately this function errors for non-numeric input.

Please login to add a comment or rating.
Updates
02 Dec 2004

fixed a bug; and does not require FINDARRAY

02 Dec 2004

included the reason why matlab function INTERSECT can't be used for the same task always

03 Dec 2004

corrected description which was mistyped

31 Aug 2005

simpler code

Tag Activity for this File
Tag Applied By Date/Time
matrices Mukhtar Ullah 22 Oct 2008 07:36:50
row Mukhtar Ullah 22 Oct 2008 07:36:50
indices Mukhtar Ullah 22 Oct 2008 07:36:50
array Mukhtar Ullah 22 Oct 2008 07:36:50
utilities Mukhtar Ullah 22 Oct 2008 07:36:50
matrix manipulation Mukhtar Ullah 22 Oct 2008 07:36:50
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com