Finding maximum value of a column in a matrix

Hello, I would really appreciate any help I can get here. I have a 3x5 matrix, A= [4 9 7 8 8; 2 1 0 3 5; 6 3 3 2 1]. I want to find the maximum value in column 1 and have the output display the corresponding row values of that maximum value. That is B = [6 3 3 2 1]. Please how can I achieve that? Thank you.

 Respuesta aceptada

James Tursa
James Tursa el 26 de Jun. de 2017
[~,x] = max(A(:,1));
B = A(x,:);

4 comentarios

Andrei Bobrov
Andrei Bobrov el 26 de Jun. de 2017
Editada: Andrei Bobrov el 26 de Jun. de 2017
>> A= [4 9 7 8 8; 6 1 0 3 5; 6 3 3 2 1]
A =
4 9 7 8 8
6 1 0 3 5
6 3 3 2 1
>> B = A(A(:,1) == max(A(:,1)),:)
B =
6 1 0 3 5
6 3 3 2 1
>>
Chiamaka Agwuegbo
Chiamaka Agwuegbo el 26 de Jun. de 2017
Thank you James. What if i have 2 maximum values in matrix A, that is A= [4 9 7 8 8; 6 1 0 3 5; 6 3 3 2 1]. is it possible to display the two corresponding rows? that is B = [6 1 0 3 5; 6 3 3 2 1]
Chiamaka Agwuegbo
Chiamaka Agwuegbo el 26 de Jun. de 2017
Thank you Andrei. It worked perfect.
raqib Iqbal
raqib Iqbal el 3 de Jul. de 2020
How to run this in a loop like after finding max value of column1 ,it will display and den find the next max value from that same column1?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Jun. de 2017

Comentada:

el 3 de Jul. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by