How to sort vector with respect to another vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Vishal Sharma
am 3 Feb. 2017
Kommentiert: Matin Salehi
am 12 Jul. 2019
I have one vector
A= [11; 12; 13; 21; 22; 31] A = 11 12 13 21 22 31
And another vector B = [5; 2; 1; 3; 4; 6] B = 5 2 1 3 4 6
I want results in new matrix with rankings as per vector B and values of A vector, so that result shall be 22 12 11 13 21 31
0 Kommentare
Akzeptierte Antwort
Guillaume
am 3 Feb. 2017
What you're asking is simple indexing:
A = [11; 12; 13; 21; 22; 31];
B = [5; 2; 1; 3; 4; 6]
result = A(B)
1 Kommentar
Matin Salehi
am 12 Jul. 2019
hi, I would b grateful if you help me regarding this question. how can I rank a matrix for example A = [ 12 14 16;15 18 20; 12 78 98] with a vector B = [2 1 3]
that the answer be like : the scond column of A come first, and the first column of A move to second column, and then 3? like C= [ 14 12 16; 18 15 20; 68 12 98]
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices 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!