how to Select a particular column with maximum values?

I generate a martix of say dimension 10*5; from this matrix I have to select the best column. Final matrix is of order 10*1.
How to generate it? using max it gives a row, not column.

 Respuesta aceptada

try this:
A=randi(100,10,5)
A = 10×5
34 35 20 71 47 96 61 66 73 66 80 43 91 25 50 64 78 80 56 37 55 22 45 68 69 5 85 7 50 57 88 64 16 35 41 77 83 77 34 81 66 32 44 50 75 56 19 42 96 27
output=max(A,[],2)
output = 10×1
71 96 91 80 69 85 88 83 75 96

6 comentarios

Thanks, but I have to choose the complete column, and not the max value in each row.
Here, it is creating a new column which is basically a combination of only max values in a row.
Torsten
Torsten el 16 de Mzo. de 2022
Editada: Torsten el 16 de Mzo. de 2022
And how do you then define "maximality" for a column ? Is it the one with its elements added is maximum ? Or the one with most elements being maximal in comparison to the corresponding elements of the other columns ?
can you show us your expected result. not clear about your question.
Chetan Fadnis
Chetan Fadnis el 16 de Mzo. de 2022
Editada: Chetan Fadnis el 16 de Mzo. de 2022
Thanks, I have to select a matrix of order say 10*1 from a matrix of order say 10*5, for this the decision criterion for selecting a column is to take norm on each column, for that I used vecnorm function. The highest value of vecnorm (1*5 matrix) will decide which column to select.
suppose 3rd element in vecnorm array is highest among all five, select that 3rd column from the 10*5 matrix.
try this:
A=randi(100,10,5)
A = 10×5
23 95 18 65 73 98 76 3 43 92 6 50 6 40 54 42 24 29 76 63 15 36 41 12 27 11 70 9 87 44 13 28 48 83 49 92 62 85 21 50 45 68 76 1 48 47 7 18 50 39
B=vecnorm(A)
B = 1×5
158.5749 182.6855 136.3855 176.0511 179.0782
[M I]=max(B) % index(column no) of maximum value
M = 182.6855
I = 2
output=A(:,I)
output = 10×1
95 76 50 24 36 70 28 62 68 7
Thanks...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear Algebra en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Mzo. de 2022

Comentada:

el 16 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by