How can I find the indices of the 3 largest values in my matrix?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Andrei Bobrov
2013-5-7
A = [99 45 93 64;
12 83 24 85
39 71 29 13];
[ii,ii] = sort(A(:),'descend');
out = ii(1:3);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!