【问题标题】:Octave time series Moving average八度时间序列移动平均线
【发布时间】:2011-03-08 01:35:03
【问题描述】:

我有一个矩阵,每列代表一个随时间变化的特征。我需要找到给定窗口大小的这些值的移动平均值。

MATLAB 中是否有类似one 的函数?

output = tsmovavg(vector, 's', lag, dim)

【问题讨论】:

    标签: matlab signal-processing time-series octave financial


    【解决方案1】:

    您可以使用FILTER 函数。一个例子:

    t = (0:.001:1)';                                %#'
    vector = sin(2*pi*t) + 0.2*randn(size(t));      %# time series
    
    wndw = 10;                                      %# sliding window size
    output1 = filter(ones(wndw,1)/wndw, 1, vector); %# moving average
    

    甚至使用图像包中的IMFILTERFSPECIAL

    output2 = imfilter(vector, fspecial('average', [wndw 1]));
    

    最后一个选项是使用索引(不推荐用于非常大的向量)

    %# get indices of each sliding window
    idx = bsxfun(@plus, (1:wndw)', 0:length(vector)-wndw);
    %'# compute average of each
    output3 = mean(vector(idx),1);
    

    请注意padding的区别:output1(wndw:end)对应output3

    【讨论】:

    • 如何设置移动平均起始样本?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 2021-10-25
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    相关资源
    最近更新 更多