MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   八度时间序列移动平均值 (https://www.labfans.com/bbs/showthread.php?t=23588)

poster 2019-12-10 20:41

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

有没有像一个功能[URL="http://www.mathworks.com/help/finance/tsmovavg.html"]一个[/URL]在MATLAB?

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

[B]回答:[/B]

您可以使用[URL="http://octave.sourceforge.net/octave/function/filter.html"]FILTER[/URL]功能。一个例子:

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 甚至使用映像包中的[URL="http://octave.sourceforge.net/image/function/imfilter.html"]IMFILTER[/URL]和[URL="http://octave.sourceforge.net/image/function/fspecial.html"]FSPECIAL[/URL]

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); 请注意填充的区别: output1(wndw:end)对应于output3



[url=https://stackoverflow.com/questions/3114450]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:33

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.