How can I find the indices of the 3 largest values in my matrix?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a matrix with varying values. I want to find the 3 largest values in this matrix and assign their indices to 3 different variables. How can I do this as simply as possible? Example matrix:
99 45 93 64
12 83 24 85
39 71 29 13
After finding the largest values - 99,93,85. I'd like to find their respective indices (with linear indexing). So that would be 1,7,11.
a = 1;
b = 7;
c = 11;
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 7 Mai 2013
A = [99 45 93 64;
12 83 24 85
39 71 29 13];
[ii,ii] = sort(A(:),'descend');
out = ii(1:3);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!