assign order to different vector

조회 수: 1 (최근 30일)
Raphael
Raphael 2012년 6월 11일
hey
i want to determine the order of every element in a vector and apply this order to another vector. say i have a vector [0, 1, -1, 3, 5] so when ordering this vector according to its size one would have 2,3,1,4,5. So now i want to transfer this order to a second vector which is ordered by size in the following way: [10, 11, 12, 13, 14]. Applying the order of the first vector this would yield: [11, 12, 10, 13, 14]. How can this performed in matlab?
thanks for your help!
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 6월 11일
How do you figure that 2,3,1,4,5 is the order for [0, 1, -1, 3, 5] ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 6월 11일
[junk, idx] = sort(A);
reordered_B = B(idx);

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by