How can I find the indices of the 3 largest values in my matrix?

3 ビュー (過去 30 日間)
Jake
Jake 2013 年 5 月 7 日
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;

採用された回答

Andrei Bobrov
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 ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by