【问题标题】:Matlab: count and sort data results in an inverse cumulative orderMatlab:以逆累积顺序对数据结果进行计数和排序
【发布时间】:2015-07-04 19:38:46
【问题描述】:

我有一个脚本可以累积我的数据并在之后绘制它。在我的例子中,我的数据是温度,图表显示了每年达到这些温度和以下每个温度的小时数。

例如:

  • 一年 7500 小时内的温度为 25 度及以下
  • 一年 6000 小时内的温度为 20 度及以下

我使用下面的 matlab 脚本得到了我需要的结果:

    filenameTRY2035='TZ10.dat';
    daten = dlmread(filenameTRY2035);
    TZ10 = sort(daten(1:length(daten)));

    A = length(TZ7); A = A';

    % plot
    figure(1)
    clf(1)

    hold on;
    h1 = plot(TZ10,A);

现在我想反过来计算温度。

例如:

  • 每年 1000 小时内的温度为 25 度及以上
  • 一年 3500 小时内气温为 20 度以上

谁能帮我修改我的脚本以获得所需的情节?

非常感谢, 夏安

【问题讨论】:

    标签: matlab cumulative-sum


    【解决方案1】:

    假设你有

    TZ10 =
    
            .... 7000  7300  7500 ....
    

    7500 -> 25° 或更冷

    7300 -> 24° 或更冷

    7000 -> 23° 或更冷

    ...

    一年有 8766 小时。

    那么相反的顺序就是

    l = length(TZ10);
    TZ10_reverse(l) = 8766 - TZ10(1)
    for temp = 2:l
        TZ10_reverse(l - temp + 1) = (8766 - TZ10(temp)) + (TZ10(temp) - TZ10(temp - 1));
    end
    

    因为如果一年有 8766 小时和 7500 小时等于或低于 25° 一年,那么有 8766 - 7500 严格 一年比 25° 暖和 TZ10(25) - TZ10 (24) 天等于 25°

    我也这样做是为了对其进行排序!

    顺便说一句....

    TZ10 = sort(daten(1:length(daten)));
    

    等价于

    TZ10 = sort(daten);
    

    daten的元素从1到daten的最大索引基本就是daten本身!

    【讨论】:

    • 没问题!不要忘记将答案检查为“已接受”;)
    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    相关资源
    最近更新 更多