I need to order a list that is dependant on another list. how to change both lists?
I have a Matlab program that generates a list x = 6.1692 8.1863 5.8092 8.2754 6.0891 the program also outputs another list aspl = 680 637 669 599 693.
The two lists are on equal length and the first element in list x is related to the first element in list aspl. I need to graph the two lists but want list aspl to be in order from smallest to largest. How would I go about doing this? If I need to move the first element in aspl to position 4 in the list, then the first element of list x also needs to be moved to position 4 in list x. The numbers above are not important they are just examples, the actual program generates hundereds of numbers.
for example x = 6.1692 8.1863 5.8092 8.2754 initially
aspl = 680 637 669 599 693
after changing aspl to ascending order this is how x should look.
x = 5.80开发者_如何学Go92 8.1863 5.8092 6.1692 8.2754
aspl = 599 637 669 680 693
Use the second output of sort:
%# sort aspl, get new order of aspl
[sortedAspl, sortOrder] = sort(aspl);
%# reorder x the same way as aspl
sortedX = x(sortOrder);
精彩评论