Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Selecting first n elements of V that meet criteria

Subject: Selecting first n elements of V that meet criteria

From: Ulrik Nash

Date: 23 Jan, 2012 21:57:10

Message: 1 of 3

Suppose I have a vector V

V = [1;0;1;1;0;1;1;0;0;1]

Now suppose I wish to create a second vector, S, which consists of the index values for the first n elements of V equal to 1.

So for example, assuming n = 3, the code should generate:

S = [1;3;4]

How might that be done?

Subject: Selecting first n elements of V that meet criteria

From: dpb

Date: 23 Jan, 2012 22:09:55

Message: 2 of 3

On 1/23/2012 3:57 PM, Ulrik Nash wrote:
...

> ... I wish to create a second vector, S, which consists of the
> index values for the first n elements of V equal to 1.

...

doc find % NB optional second argument

--

Subject: Selecting first n elements of V that meet criteria

From: Ulrik Nash

Date: 23 Jan, 2012 22:28:10

Message: 3 of 3

dpb <none@non.net> wrote in message <jfklrh$k3c$1@speranza.aioe.org>...
> On 1/23/2012 3:57 PM, Ulrik Nash wrote:
> ...
>
> > ... I wish to create a second vector, S, which consists of the
> > index values for the first n elements of V equal to 1.
>
> ...
>
> doc find % NB optional second argument
>
> --
Thank you dpb! :-)

Tags for this Thread

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.

Contact us