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 values in a vector, based on index of another vector

Subject: Selecting values in a vector, based on index of another vector

From: Ulrik Nash

Date: 8 Jul, 2010 10:15:09

Message: 1 of 4

Hi Everyone,

Suppose I have a vector of firm ID's (a sub selection of the entire population)

firm_id_selection = [1 3 4]

and I have another vector of firm prices for each firm in a population (in this case there are 5 firms in the population):

firm_prices_all = [10.25 11.00 9.75 22.50 10.99]

QUESTION: How do I select the prices of the firms in firm_id_selection (that is to say, select the 1st 3rd and 4th price in firm_prices_all) to create:

firm_prices_selection = [10.25 9.75 22.50]

Regards

Ulrik.

Subject: Selecting values in a vector, based on index of another vector

From: Jan Simon

Date: 8 Jul, 2010 10:44:06

Message: 2 of 4

Dear Ulrik,

> firm_id_selection = [1 3 4]
> firm_prices_all = [10.25 11.00 9.75 22.50 10.99]
> firm_prices_selection = [10.25 9.75 22.50]

Read the "Getting started" section of the docs. There you find a very well explanaition of the basic indexing methods.

Good luck and welcome to Matlab, Jan

Subject: Selecting values in a vector, based on index of another vector

From: Ulrik Nash

Date: 8 Jul, 2010 11:01:04

Message: 3 of 4

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i14a5m$74p$1@fred.mathworks.com>...
> Dear Ulrik,
>
> > firm_id_selection = [1 3 4]
> > firm_prices_all = [10.25 11.00 9.75 22.50 10.99]
> > firm_prices_selection = [10.25 9.75 22.50]
>
> Read the "Getting started" section of the docs. There you find a very well explanaition of the basic indexing methods.
>
> Good luck and welcome to Matlab, Jan


Thanks Jan. It turns out to be quite easy:

firm_prices_selection = ([firm_id_selection])

Subject: Selecting values in a vector, based on index of another vector

From: Jan Simon

Date: 8 Jul, 2010 14:29:07

Message: 4 of 4

Dear Ulrik,

> > > firm_id_selection = [1 3 4]
> > > firm_prices_all = [10.25 11.00 9.75 22.50 10.99]
> > > firm_prices_selection = [10.25 9.75 22.50]

> firm_prices_selection = ([firm_id_selection])

You mean:
  firm_prices_selection = firm_prices_all(firm_id_selection)

Jan

Tags for this Thread

No tags are associated with 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