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:
Find value in second column when first column is x.

Subject: Find value in second column when first column is x.

From: Aaron Anstey

Date: 10 Aug, 2010 19:43:06

Message: 1 of 5

I have a matrix of two columns, the first column contains a range of numbers and so does the second column. When the value in the first column is "50", I want Matlab to output the corresponding value for that row in the second column.
Can anyone please tell me the command I can use for this?
Many thanks.

Subject: Find value in second column when first column is x.

From: dpb

Date: 10 Aug, 2010 19:45:59

Message: 2 of 5

Aaron Anstey wrote:
> I have a matrix of two columns, the first column contains a range of
> numbers and so does the second column. When the value in the first
> column is "50", I want Matlab to output the corresponding value for that
> row in the second column. Can anyone please tell me the command I can
> use for this? Many thanks.

doc find

--

Subject: Find value in second column when first column is x.

From: Andy

Date: 10 Aug, 2010 19:51:05

Message: 3 of 5

"Aaron Anstey" <elaja2@lboro.ac.uk> wrote in message <i3sa4a$c7m$1@fred.mathworks.com>...
> I have a matrix of two columns, the first column contains a range of numbers and so does the second column. When the value in the first column is "50", I want Matlab to output the corresponding value for that row in the second column.
> Can anyone please tell me the command I can use for this?
> Many thanks.

Does "output" mean at the command line?

>> a=[(1:100)' rand(100,1)]; % sample data
>> a(a(:,1)==50,2) % outputs the second column where the first column is 50

Subject: Find value in second column when first column is x.

From: machatsk

Date: 10 Aug, 2010 19:51:06

Message: 4 of 5

"Aaron Anstey" <elaja2@lboro.ac.uk> wrote in message <i3sa4a$c7m$1@fred.mathworks.com>...
> I have a matrix of two columns, the first column contains a range of numbers and so does the second column. When the value in the first column is "50", I want Matlab to output the corresponding value for that row in the second column.
> Can anyone please tell me the command I can use for this?
> Many thanks.

matrix(50,2) %gets value of 50th row, 2nd column
             Maxx

Subject: Find value in second column when first column is x.

From: Aaron Anstey

Date: 10 Aug, 2010 20:31:05

Message: 5 of 5

"Andy " <myfakeemailaddress@gmail.com> wrote in message <i3saj9$cpq$1@fred.mathworks.com>...
> "Aaron Anstey" <elaja2@lboro.ac.uk> wrote in message <i3sa4a$c7m$1@fred.mathworks.com>...
> > I have a matrix of two columns, the first column contains a range of numbers and so does the second column. When the value in the first column is "50", I want Matlab to output the corresponding value for that row in the second column.
> > Can anyone please tell me the command I can use for this?
> > Many thanks.
>
> Does "output" mean at the command line?
>
> >> a=[(1:100)' rand(100,1)]; % sample data
> >> a(a(:,1)==50,2) % outputs the second column where the first column is 50

Many thanks, this works.

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