Extract top 10 values from each row
Ältere Kommentare anzeigen
Hello,
I have a matrix and wish to keep only the top 10 values in each row and replace all the other (bottom 90) values with zeros. Is there an efficient way to achieve this?
Akzeptierte Antwort
Weitere Antworten (1)
Laura Proctor
am 10 Okt. 2011
This code will keep the top ten rows and replaces everything from the 11th row on with a zero.
A = rand(100);
A(11:end,:) = 0;
4 Kommentare
Fangjun Jiang
am 10 Okt. 2011
Maybe need to sort first?
Laura Proctor
am 10 Okt. 2011
For the maximum values, you will need to sort:
A = sort(A,'descend');
A(11:end,:) = 0;
Saurabh
am 10 Okt. 2011
Saurabh
am 10 Okt. 2011
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!