how to Select a particular column with maximum values?

1 Ansicht (letzte 30 Tage)
Chetan Fadnis
Chetan Fadnis am 16 Mär. 2022
Kommentiert: Chetan Fadnis am 16 Mär. 2022
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.

Akzeptierte Antwort

Arif Hoq
Arif Hoq am 16 Mär. 2022
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 Kommentare
Arif Hoq
Arif Hoq am 16 Mär. 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by