代码之家  ›  专栏  ›  技术社区  ›  user3052817

如何在Matlab中找到最小10%的数据?

  •  2
  • user3052817  · 技术社区  · 7 年前

    我尝试使用排序函数(从这里: https://www.mathworks.com/matlabcentral/answers/249619-how-do-i-get-the-top-10-percent-of-the-matrix-value )但时间已不再按时间顺序排列。这是我使用的代码:

    [sortedValues,sortIndex] = sort(THUL_ST_JJA(:),'ascend'); %Sort Ascending
    [sortedDTValues,sortDTIndex] = sort(THUL_dt_JJA(:),'ascend'); %Sort Ascending
    
    idx = sortIndex(1:ceil(length(sortIndex)*0.1)); %Minimum 10th percent STs
    THUL_ST_min = THUL_ST_JJA(idx);
    THUL_dt_min = THUL_dt_JJA(idx); %Find matching 10th percent minimum times 
    

    以下是时间(mm/dd/yyyy hh:mm:ss)和温度无序的示例:

    06/08/2012 07:00:00 -5.26
    06/08/2012 10:00:00 -5.18
    06/08/2012 09:00:00 -5.1
    06/08/2012 08:00:00 -5.07
    06/08/2012 06:00:00 -4.84
    06/08/2012 11:00:00 -4.84
    06/09/2012 06:00:00 -4.84
    06/09/2012 07:00:00 -4.82
    06/09/2012 05:00:00 -4.79
    06/09/2012 08:00:00 -4.65
    08/29/2012 05:00:00 -4.61
    06/09/2012 09:00:00 -4.49
    08/29/2012 06:00:00 -4.47
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Aero Engy    7 年前

    对数据进行排序。然后使用相同的索引对时间进行排序。这使配对保持在一起。

    然后获取所需数据的索引&对时间应用相同的索引。

    [sortData, sortIDX] = sort(rawData,'ascend');
    sortTime            = rawTime(sortIDX);
    
    bottom10IDX = 1:ceil(length(sortData)*0.1);
    bottom10Data = sortData(bottom10IDX);
    bottom10Time = sortTime(bottom10IDX);