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

New to MATLAB?

Return the number of the row that contains the largest value in column vectors

Asked by John

John

on 4 Feb 2012
Latest activity Edited by Cedric Wannaz

Cedric Wannaz

on 30 Sep 2013
Accepted Answer by the cyclist

the cyclist

Hi there,

Is there a way in matlab to return the number of a row that contains the largest value?

For example, for the following matrix

0.14	0	0.99	1	0
0.73	0.93	0.02	0	0
0	0	0	0	0.99
0	0	0.01	0	0
0.01	0.05	0.03	0.01	0
0	0.02	0	0	0.02
0.01	0	0.01	0	0

How could you make it return 2 2 1 1 3?

Many thanks John

0 Comments

John

John

Tags

Products

No products are associated with this question.

1 Answer

Answer by the cyclist

the cyclist

on 4 Feb 2012
Accepted answer

The second output argument of the max() function will do this:

 [m index] = max(x)

where x is your matrix. Note that by default, max() works down the columns of a matrix. Read "doc max" for more details.

1 Comment

John

John

on 4 Feb 2012

Thanks very much.

the cyclist

the cyclist

Contact us