Thread Subject: how to get index of seeked element in vector?

Subject: how to get index of seeked element in vector?

From: Patrick R

Date: 3 Mar, 2009 21:30:24

Message: 1 of 5

i have managed to get a cell array "found" which looks like this:
0 0 0 1 0 0 0 0 0 0

now I would need a function that returns the index of the "1", i.e. in this example "4".
can anybody please help me with this (for me tricky) problem? :)

thanks, patrick

Subject: how to get index of seeked element in vector?

From: Matt Fig

Date: 3 Mar, 2009 21:37:02

Message: 2 of 5

"Patrick R" <p.reichmann@inode.at> wrote in message <gok7hg$o02$1@fred.mathworks.com>...
> i have managed to get a cell array "found" which looks like this:
> 0 0 0 1 0 0 0 0 0 0
>
> now I would need a function that returns the index of the "1", i.e. in this example "4".
> can anybody please help me with this (for me tricky) problem? :)
>
> thanks, patrick


Is it a cell array or a vector, you seem to indicate both. Have a look at the find function.




9g^fxebbRhFnxxZi[m ahxhZd^fam`'xn[Z^^Zxa>ZoiZm3rhhZ\\xgxe h

Subject: how to get index of seeked element in vector?

From: Patrick R

Date: 3 Mar, 2009 21:37:02

Message: 3 of 5

btw. one solution that works is following:

wbIDX = 1;
while found(wbIDX) ~= 1
    wbIDX = wbIDX + 1;
end

but I think there must be a nicer solution without a loop?


"Patrick R" <p.reichmann@inode.at> wrote in message <gok7hg$o02$1@fred.mathworks.com>...
> i have managed to get a cell array "found" which looks like this:
> 0 0 0 1 0 0 0 0 0 0
>
> now I would need a function that returns the index of the "1", i.e. in this example "4".
> can anybody please help me with this (for me tricky) problem? :)
>
> thanks, patrick

Subject: how to get index of seeked element in vector?

From: Patrick R

Date: 3 Mar, 2009 21:43:03

Message: 4 of 5

"Matt Fig" <spamanon@yahoo.com> wrote in message <gok7tu$l5e$1@fred.mathworks.com>...
> "Patrick R" <p.reichmann@inode.at> wrote in message <gok7hg$o02$1@fred.mathworks.com>...
> > i have managed to get a cell array "found" which looks like this:
> > 0 0 0 1 0 0 0 0 0 0
> >
> > now I would need a function that returns the index of the "1", i.e. in this example "4".
> > can anybody please help me with this (for me tricky) problem? :)
> >
> > thanks, patrick
>
>
> Is it a cell array or a vector, you seem to indicate both. Have a look at the find function.
>
>

well I generated it with the isempty function and matlab says it's a <1x10> logical
guess it's a vector now *blush*

Subject: how to get index of seeked element in vector?

From: Patrick R

Date: 3 Mar, 2009 21:46:03

Message: 5 of 5

"Patrick R" <p.reichmann@inode.at> wrote in message <gok897$fl3$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote in message <gok7tu$l5e$1@fred.mathworks.com>...
> > "Patrick R" <p.reichmann@inode.at> wrote in message <gok7hg$o02$1@fred.mathworks.com>...
> > > i have managed to get a cell array "found" which looks like this:
> > > 0 0 0 1 0 0 0 0 0 0
> > >
> > > now I would need a function that returns the index of the "1", i.e. in this example "4".
> > > can anybody please help me with this (for me tricky) problem? :)
> > >
> > > thanks, patrick
> >
> >
> > Is it a cell array or a vector, you seem to indicate both. Have a look at the find function.
> >
> >
>
> well I generated it with the isempty function and matlab says it's a <1x10> logical
> guess it's a vector now *blush*


ooooh, the "find"-function works perfectly, I knew it had to be as simple as that =)
thanks alot

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