我需要订购依赖于另一个列表的列表.如何更改两个列表? [英] I need to order a list that is dependant on another list. how to change both lists?

查看:54
本文介绍了我需要订购依赖于另一个列表的列表.如何更改两个列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Matlab程序,该程序生成一个列表x = 6.1692 8.1863 5.8092 8.2754 6.0891该程序还输出另一个列表aspl =680637669669599693.

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.

两个列表的长度相等,并且列表x中的第一个元素与列表aspl中的第一个元素相关.我需要绘制两个列表的图,但希望列表aspl从最小到最大依次排列.我将如何去做呢?如果我需要将aspl中的第一个元素移动到列表中的位置4,那么列表x中的第一个元素也需要移动到列表x中的位置4.上面的数字并不重要,它们只是示例,实际的程序会产生混乱的数字.

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.

例如,最初x = 6.1692 8.1863 5.8092 8.2754

for example x = 6.1692 8.1863 5.8092 8.2754 initially

     aspl =  680   637   669   599   693

将aspl更改为升序后,这就是x的外观.

after changing aspl to ascending order this is how x should look.

x = 5.8092 8.1863 5.8092 6.1692 8.2754

x = 5.8092 8.1863 5.8092 6.1692 8.2754

aspl = 599637669680693

aspl = 599 637 669 680 693

推荐答案

使用sort的第二个输出:

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);

这篇关于我需要订购依赖于另一个列表的列表.如何更改两个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆