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

采纳的回答

Guillaume
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
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 CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by