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 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!