How to locate number from a matrix

1 visualizzazione (ultimi 30 giorni)
Kaijia Chen
Kaijia Chen il 30 Nov 2021
Commentato: KSSV il 30 Nov 2021
I have matrix list2, it's a 526x2 double. Suppose the first column represents the ID of people, and the second column represents the total amount of films they shot. I want to find out the N most prolific films shot by the people. I used sort(list2(:,2),'descend') to rearrange the second colomn to get the most movie shot to the least. However, I also need to determine the people's ID, so the question is how to relocate back to the person's ID if we have the information of the second column?

Risposta accettata

KSSV
KSSV il 30 Nov 2021
If idx is the indices of the locations in second column...to get the respective first column just use:
iwant = list2(idx,1)
  5 Commenti
Kaijia Chen
Kaijia Chen il 30 Nov 2021
So I rearrange the second column because I wanna find the people in descending order. The problem is how to relocate the first column in the same order? Thank you!
KSSV
KSSV il 30 Nov 2021
A = rand(10,2) ;
[val,idx] = sort(A(:,2)) ;
iwant = A(idx,1)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by