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:
select the whole row of the max value in the second column

Subject: select the whole row of the max value in the second column

From: Reza Reza

Date: 2 Nov, 2010 15:47:04

Message: 1 of 5

Hi,
can you pls help me with this matlab code:
I have an array like the following:
A=[2 3 4; 3 7 2; 4 12 4]
so 12 is the max value in the second column .
how can I select the whole row of the max value in the second column ?
thanks

Subject: select the whole row of the max value in the second column

From: Jos (10584)

Date: 2 Nov, 2010 15:54:03

Message: 2 of 5

"Reza Reza" <persianfriend12@yahoo.com> wrote in message <iapbpo$mir$1@fred.mathworks.com>...
> Hi,
> can you pls help me with this matlab code:
> I have an array like the following:
> A=[2 3 4; 3 7 2; 4 12 4]
> so 12 is the max value in the second column .
> how can I select the whole row of the max value in the second column ?
> thanks

a hint:

[m,idx] = max(A(:,2))

Jos

Subject: select the whole row of the max value in the second column

From: Sean

Date: 2 Nov, 2010 16:01:05

Message: 3 of 5

"Reza Reza" <persianfriend12@yahoo.com> wrote in message <iapbpo$mir$1@fred.mathworks.com>...
> Hi,
> can you pls help me with this matlab code:
> I have an array like the following:
> A=[2 3 4; 3 7 2; 4 12 4]
> so 12 is the max value in the second column .
> how can I select the whole row of the max value in the second column ?
> thanks

[~,idr] = max(A(:,2));
A(idr,:)

ans =

     4 12 4

Subject: select the whole row of the max value in the second column

From: Reza Reza

Date: 2 Nov, 2010 16:12:04

Message: 4 of 5

thanks

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iapck1$goa$1@fred.mathworks.com>...
> "Reza Reza" <persianfriend12@yahoo.com> wrote in message <iapbpo$mir$1@fred.mathworks.com>...
> > Hi,
> > can you pls help me with this matlab code:
> > I have an array like the following:
> > A=[2 3 4; 3 7 2; 4 12 4]
> > so 12 is the max value in the second column .
> > how can I select the whole row of the max value in the second column ?
> > thanks
>
> [~,idr] = max(A(:,2));
> A(idr,:)
>
> ans =
>
> 4 12 4

Subject: select the whole row of the max value in the second column

From: Greg Heath

Date: 3 Nov, 2010 01:18:21

Message: 5 of 5

On Nov 2, 11:47 am, "Reza Reza" <persianfrien...@yahoo.com> wrote:
> Hi,
> can you pls help me with this matlab code:
> I have an array like the following:
> A=[2 3 4; 3 7 2; 4  12  4]
> so 12 is the max value in the second column .
> how can I select the whole row of the max value in the second column ?
> thanks

If the second column has multiple maxima,which
row(s) do you want? e.g.,

A=[2 12 4; 3 7 2; 4 12 4]

Greg

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