Thread Subject: position in a vector

Subject: position in a vector

From: halee Rustumani

Date: 20 Dec, 2009 19:52:03

Message: 1 of 4

Hello everyone
I have a question let say you have a vector
x=[5 1 8 2]
And you want to specify the location (indice) of any number in that vector
 For example you want the position of the 8 the output of the program should be 4.
Any suggestions
thanks

Subject: position in a vector

From: Matt Fig

Date: 20 Dec, 2009 19:58:03

Message: 2 of 4

"halee Rustumani" <halee89@hotmail.com> wrote in message <hglv93$896$1@fred.mathworks.com>...
> Hello everyone
> I have a question let say you have a vector
> x=[5 1 8 2]
> And you want to specify the location (indice) of any number in that vector
> For example you want the position of the 8 the output of the program should be 4.
> Any suggestions
> thanks

Shouldn't the position of the 8 be 3, not 4? Here is one approach, with the usual FP warnings:


pos = find(x==8)

Subject: position in a vector

From: halee Rustumani

Date: 20 Dec, 2009 20:24:03

Message: 3 of 4

"Matt Fig" <spamanon@yahoo.com> wrote in message <hglvkb$ss5$1@fred.mathworks.com>...
> "halee Rustumani" <halee89@hotmail.com> wrote in message <hglv93$896$1@fred.mathworks.com>...
> > Hello everyone
> > I have a question let say you have a vector
> > x=[5 1 8 2]
> > And you want to specify the location (indice) of any number in that vector
> > For example you want the position of the 8 the output of the program should be 4.
> > Any suggestions
> > thanks
>
> Shouldn't the position of the 8 be 3, not 4? Here is one approach, with the usual FP warnings:
>
>
> pos = find(x==8)
yessss your right im sorry and yes it works thanks alot :)

Subject: position in a vector

From: Jan Simon

Date: 21 Dec, 2009 09:00:19

Message: 4 of 4

Dear halee!

> pos = find(x==8)

Sometimes faster - and working for double vectors also inspite of the name:
  pos = findstr(x, 8)

Jan

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