How to sort vector with respect to another vector
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Guillaume
2017-2-3
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 个评论
Matin Salehi
2019-7-12
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]
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!