I need to order a list that depends 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 displays a different list aspl = 680 637 669 599 693.

The two lists are the same length, and the first element in the list x is associated with the first element in the aspl list. I need to display two lists, but want the aspl list to be in order from smallest to largest. How can I do it? If I need to move the first element in aspl to position 4 in the list, then the first element of the list x should also be moved to position 4 in the list x. The numbers above are not important, they are just examples, the actual program generates the number of lines.

e.g. x = 6.1692 8.1863 5.8092 8.2754 initially

aspl = 680 637 669 599 693 

after changing aspl in ascending order, what x should look like.

x = 5.8092 8.1863 5.8092 6.1692 8.2754

aspl = 599 637 669 680 693

+4
source share
1 answer

Use the second sort output:

 %# sort aspl, get new order of aspl [sortedAspl, sortOrder] = sort(aspl); %# reorder x the same way as aspl sortedX = x(sortOrder); 
+8
source

Source: https://habr.com/ru/post/1305059/


All Articles