我需要订购一个依赖于另一个列表的列表.如何更改两个列表?

Ben*_*sen 4 matlab list

我有一个Matlab程序生成一个列表x = 6.1692 8.1863 5.8092 8.2754 6.0891该程序还输出另一个列表aspl = 680 637 669 599 693.

这两个列表的长度相等,列表x中的第一个元素与列表aspl中的第一个元素相关.我需要绘制两个列表的图形,但希望列表aspl按从小到大的顺序排列.我该怎么做呢?如果我需要将aspl中的第一个元素移动到列表中的第4位,那么列表x的第一个元素也需要移动到列表x中的位置4.上面的数字并不重要,它们只是例子,实际的程序产生数字.

例如,x = 6.1692 8.1863 5.8092 8.2754最初

     aspl =  680   637   669   599   693
Run Code Online (Sandbox Code Playgroud)

在将aspl更改为升序之后,这应该是x的外观.

x = 5.8092 8.1863 5.8092 6.1692 8.2754

aspl = 599 637 669 680 693

Jon*_*nas 8

使用排序的第二个输出:

%# sort aspl, get new order of aspl
[sortedAspl, sortOrder] = sort(aspl);
%# reorder x the same way as aspl
sortedX = x(sortOrder);
Run Code Online (Sandbox Code Playgroud)