Help with finding index

  • Follow


I have an array of say :

 a =

     2     3     4
     5     6     2
     4     2     1
     7     2     4

I want to find the index of an exact vector.
For instance,  I want to find the row index of vector [4 2 1], answer is 3(row 3).
The vector [7 2 4] will return index 4.

The find function does not work , any suggestion.
0
Reply ade77 11/20/2009 10:37:19 PM

ade77 wrote:
> I have an array of say :
....>
> I want to find the index of an exact vector.
> For instance,  I want to find the row index of vector ...

doc intersect

--
0
Reply dpb 11/20/2009 10:45:50 PM


dpb <none@non.net> wrote in message <he7677$3mi$1@news.eternal-september.org>...
> ade77 wrote:
> > I have an array of say :
> ...>
> > I want to find the index of an exact vector.
> > For instance,  I want to find the row index of vector ...
> 
> doc intersect
> 
> --

Thank you. Works perfectly
0
Reply ade77 11/20/2009 10:55:19 PM

Hi,

the "Intersect" function works well in this case, but if  I have this matrix

a =

     4 2 1
     5 6 2
     4 2 1
     7 2 4

And, If I want to find "all' rows index of vector [4 2 1], answers are rows 1 and 3.
[i,ii,iii]=Intersect(a,[4 2 1],'rows')  give just the last row index, (3) in this case.
0
Reply LCPC 12/9/2009 3:46:31 PM

Look at ismember with the rows option.
0
Reply Matt 12/9/2009 4:49:01 PM

"LCPC Yannick" <yannick.fargier@hotmail.fr> wrote in message <hfogon$jrk$1@fred.mathworks.com>...
> Hi,
> 
> the "Intersect" function works well in this case, but if  I have this matrix
> 
> a =
> 
>      4 2 1
>      5 6 2
>      4 2 1
>      7 2 4
> 
> And, If I want to find "all' rows index of vector [4 2 1], answers are rows 1 and 3.
> [i,ii,iii]=Intersect(a,[4 2 1],'rows')  give just the last row index, (3) in this case.


STRMATCH will also work

>> strmatch([4 2 1], a)

ans =

     1
     3
0
Reply Matt 12/9/2009 7:39:20 PM

thank you Matt & Matt, it works perfectly.
0
Reply LCPC 12/10/2009 10:19:19 AM

6 Replies
146 Views

(page loaded in 0.061 seconds)

Similiar Articles:













7/15/2012 8:37:14 PM


Reply: