Thread Subject: Help with finding index

Subject: Help with finding index

From: ade77

Date: 20 Nov, 2009 22:37:19

Message: 1 of 7

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.

Subject: Help with finding index

From: dpb

Date: 20 Nov, 2009 22:45:50

Message: 2 of 7

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

--

Subject: Help with finding index

From: ade77

Date: 20 Nov, 2009 22:55:19

Message: 3 of 7

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

Subject: Help with finding index

From: LCPC Yannick

Date: 9 Dec, 2009 15:46:31

Message: 4 of 7

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.

Subject: Help with finding index

From: Matt Fig

Date: 9 Dec, 2009 16:49:01

Message: 5 of 7

Look at ismember with the rows option.

Subject: Help with finding index

From: Matt J

Date: 9 Dec, 2009 19:39:20

Message: 6 of 7

"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

Subject: Help with finding index

From: LCPC Yannick

Date: 10 Dec, 2009 10:19:19

Message: 7 of 7

thank you Matt & Matt, it works perfectly.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com