Extract top 10 values from each row
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
Laura Proctor
2011년 10월 10일
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
Fangjun Jiang
2011년 10월 10일
Maybe need to sort first?
Laura Proctor
2011년 10월 10일
For the maximum values, you will need to sort:
A = sort(A,'descend');
A(11:end,:) = 0;
Saurabh
2011년 10월 10일
Saurabh
2011년 10월 10일
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!