From: Ulrik Nash on
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.
From: Jan Simon on
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
From: Ulrik Nash on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i14a5m$74p$1(a)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])
From: Jan Simon on
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