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

4 Ansichten (letzte 30 Tage)
Hang Vu
Hang Vu am 24 Jul. 2019
Kommentiert: Hang Vu am 24 Jul. 2019
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.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 24 Jul. 2019
>> 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 Kommentare
madhan ravi
madhan ravi am 24 Jul. 2019
Alright , thank you :)
Hang Vu
Hang Vu am 24 Jul. 2019
Thank you so much for the help! and your time also.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 24 Jul. 2019
Bearbeitet: madhan ravi am 24 Jul. 2019
[~,idx]=sort(A,'descend');
B=idx(1:3)
C=setdiff(idx,B)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by