Sort one set of data to correspond to another.
Show older comments
Say I have an ordered set of data.
a = [100,200,300,400,500];
And say I have another set of data,
b = [300,200,500,400,100]
I m trying to find the index where a is sorted to b. I could use a nested for loop of course but is there a better way to get the index shown below?
c = [5,2,1,4,3]
Accepted Answer
More Answers (2)
>> a = [100,200,300,400,500];
>> b = [300,200,500,400,100];
>> [~,Xa] = sort(a);
>> [~,Xb] = sort(b);
>> Xa(Xb)
ans =
5 2 1 4 3
Guillaume
on 16 Nov 2015
x = [350,420,245,100]
k = [420,100,350,245]
z = ismember(x, k)
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!