How do I return rows of a matrix based on the value of the maximum element.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Can someone help me? I am using MATLAB R2011b and I am having problems returning rows based on the maximum value in (:, 2:end). I have two .txt files with data in the format:
A =
1901 1.0 0.9 1.4 3.0 3.9 8.3 9.5 9.4 8.8 6.6 4.1 1.7
1902 0.3 2.4 1.5 3.7 5.1 8.3 10.4 10.3 7.6 5.9 2.7 0.7
1903 0.6 0.1 0.7 2.6 4.4 7.6 9.3 10.1 7.9 4.7 -0.7 1.2
B =
1901 5.9 7.0 8.2 10.5 14.3 17.1 17.6 18.6 16.5 13.2 10.2 6.6
1902 5.4 8.6 8.2 13.5 13.8 17.9 18.8 19.3 16.8 12.9 8.9 6.1
1903 5.3 6.1 7.7 11.0 14.3 18.0 17.5 18.1 16.6 11.9 5.8 6.5
If I use:
D = [A(:,1), (B(:,2:13)-A(:,2:13))] and get:
1901 4.9 6.1 6.8 7.5 10.4 8.8 8.1 9.2 7.7 6.6 6.1 4.9
1902 5.1 6.2 6.7 9.8 8.7 9.6 8.4 9.0 9.2 7.0 6.2 5.4
1903 4.7 6.0 7.0 8.4 9.9 10.4 8.2 8.0 8.7 7.2 6.5 5.3
I expect to get:
1903 4.9 6.1 6.8 7.5 10.4 8.8 8.1 9.2 7.7 6.6 6.1 4.9
1905 4.7 6.0 7.0 8.4 9.9 10.4 8.2 8.0 8.7 7.2 6.5 5.3
13 Kommentare
DGM
am 25 Apr. 2021
It returns both rows associated with 10.4, which is the global maximum of the data difference.
"I can see 2 values in D which are the same and they are the maximums."
Which is what you were saying.
Antworten (0)
Siehe auch
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!