How to sort vector with respect to another vector
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Guillaume
on 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 Comment
Matin Salehi
on 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]
More Answers (0)
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!