如何从线性插值数据中获得每月总计

时间:2017-04-25 16:00:28

标签: matlab date linear-interpolation

我正在使用自20世纪80年代以来反复测量的10,000个变量的数据集。每个变量的第一个测量不是在同一个日期,并且变量是不规则测量的 - 有时测量只相隔一个月,在少数情况下它们相隔数十年。

我希望每月在每个变量中获得更改

到目前为止,我有一个测量日期单元格和测量之间的插值变化率(每个单元格代表一个变量,我只发布每个数组中的前5个单元格)

DateNumss= {[736614;736641;736669]  [736636;736666] 736672  [736631;736659;736685]  736686}

LinearInterpss={[17.7777777777778;20.7142857142857;0]   [0.200000000000000;0]   0   [2.57142857142857;2.80769230769231;0]}

如何获得变量中插值变化的每月总和?

即。

如果变量的第一次测量是在1月1日进行的,那么下次测量之间的线性插值变化是每天1次;下一次测量是在2月5日,相应的线性插值变化为2;然后1月份的总变化为1 * 31(1天为31天),费用总变化为1 * 5 + 2 * 23(1天为2天,2天为23天)。

1 个答案:

答案 0 :(得分:0)

您需要序列日期中与月份变化相对应的点数。

mat(:,1)=sort(repmat(1980:1989,[1,12]));
mat(:,2)=repmat(1:12,[1,size(mat,1)/12]);
mat(:,3)=1;
monthseps=datenum(mat);

这将列出八十年代所有120个月的变化。

现在,您希望每个月每天更改一次,并将其相加。如果您获取原始数据则更容易,因为您可以使用matlab插入每天的值。如果您只有“LinearInterpss”,则需要使用interp1和“previous”方法在日期中映射它。

for ct = 2:length(monthseps)
    days = monthseps(ct-1):(monthseps(ct)-1); %days in the month
    %now we need each day assigned a certain change. This value depends on your "LinearInterpss". interp1 with method 'previous' searches LineairInterpss for the last value.
    vals = interp1(DateNumss,LinearInterpss,days,'previous'); 
    sum(vals); %the sum over the change in each day is the total change in a month
end