フィルターのクリア

finding the top ten values of arrary

7 ビュー (過去 30 日間)
khaled DAWOUD
khaled DAWOUD 2012 年 7 月 21 日
Hello, I have an array a,i want to find the top ten max values and thier indexes , how i can do that , Thanks ?
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 7 月 21 日
if there are many equals numbers, what you want to do, take them all? in this case there will be more than 10 values.

サインインしてコメントする。

採用された回答

per isakson
per isakson 2012 年 7 月 21 日
編集済み: per isakson 2012 年 7 月 21 日
Try this:
M = magic(4);
N = 10;
[ b, ix ] = sort( M(:), 'descend' );
[ rr, cc ] = ind2sub( size(M), ix(1:N) );
for ii = 1 : N
disp( M( rr(ii), cc(ii) ) )
end
  1 件のコメント
khaled DAWOUD
khaled DAWOUD 2012 年 7 月 21 日
Thanks Very much , i realy appreciated you time and help

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 7 月 21 日
編集済み: Azzi Abdelmalek 2012 年 7 月 21 日
% try this
a=[1 2 7 8 8 5 20 20 40 0 1 8 77 77 87 87 52 36 87 12 78]';
c=flipud(unique(sort(a))),
result=c(1:10); %top ten
ind=find(a>=c(10)) %their indices
resultat=flipud(sortrows([a(ind) ind],1))
% because there equals number , there is more than 10 classed. if you want take only %10 include this code
resultat1=resultat(1:10,:)
  1 件のコメント
khaled DAWOUD
khaled DAWOUD 2012 年 7 月 21 日
Thanks Very much , i realy appreciated you time and help

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by