How to find the index of top k max values in the matrix

4 ビュー (過去 30 日間)
Hang Vu
Hang Vu 2019 年 7 月 24 日
コメント済み: Hang Vu 2019 年 7 月 24 日
A=[ 5 40 10 9 2 1 8 12 33 23]
find index of top 3 max values as:B= [ 2 9 10]
and return the rest index value in another array C=[1 3 4 5 6 7 8]
Thank you.

採用された回答

Bruno Luong
Bruno Luong 2019 年 7 月 24 日
>> A=[ 5 40 10 9 2 1 8 12 33 23]
A =
5 40 10 9 2 1 8 12 33 23
>> [~,B]=maxk(A,3)
B =
2 9 10
>> C=setdiff(1:length(A),B)
C =
1 3 4 5 6 7 8
  10 件のコメント
madhan ravi
madhan ravi 2019 年 7 月 24 日
Alright , thank you :)
Hang Vu
Hang Vu 2019 年 7 月 24 日
Thank you so much for the help! and your time also.

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 7 月 24 日
編集済み: madhan ravi 2019 年 7 月 24 日
[~,idx]=sort(A,'descend');
B=idx(1:3)
C=setdiff(idx,B)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by