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 で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!