【问题标题】:I need to order a list that is dependant on another list. how to change both lists?我需要订购一个依赖于另一个列表的列表。如何更改两个列表?
【发布时间】:2010-03-25 03:16:04
【问题描述】:

我有一个 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

将 aspl 更改为升序后,x 应该是这样的。

x = 5.8092 8.1863 5.8092 6.1692 8.2754

aspl = 599 637 669 680 693

【问题讨论】:

    标签: matlab list


    【解决方案1】:

    使用排序的第二个输出:

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

    【讨论】:

      猜你喜欢
      • 2020-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      相关资源
      最近更新 更多