【发布时间】:2011-03-08 01:35:03
【问题描述】:
我有一个矩阵,每列代表一个随时间变化的特征。我需要找到给定窗口大小的这些值的移动平均值。
MATLAB 中是否有类似one 的函数?
output = tsmovavg(vector, 's', lag, dim)
【问题讨论】:
标签: matlab signal-processing time-series octave financial
我有一个矩阵,每列代表一个随时间变化的特征。我需要找到给定窗口大小的这些值的移动平均值。
MATLAB 中是否有类似one 的函数?
output = tsmovavg(vector, 's', lag, dim)
【问题讨论】:
标签: matlab signal-processing time-series octave financial
您可以使用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
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
【讨论】: