我需要在for循环内计算数据序列的移动平均值.我必须获得N = 9天的移动平均线.我正在计算的数组是4个系列的365个值(M),它们本身是另一组数据的平均值.我想将数据的平均值与移动平均值一起绘制在一张图中.
I need to compute a moving average over a data series, within a for loop. I have to get the moving average over N=9 days. The array I'm computing in is 4 series of 365 values (M), which itself are mean values of another set of data. I want to plot the mean values of my data with the moving average in one plot.
我在移动平均值和"conv"命令上进行了一些搜索,发现了一些我尝试在代码中实现的东西.
I googled a bit about moving averages and the "conv" command and found something which i tried implementing in my code.:
hold on for ii=1:4; M=mean(C{ii},2) wts = [1/24;repmat(1/12,11,1);1/24]; Ms=conv(M,wts,'valid') plot(M) plot(Ms,'r') end hold off因此,基本上,我计算平均值并用(错误的)移动平均值进行绘制.我在mathworks网站附近选择了"wts"值,所以这是不正确的. (来源: www.mathworks.nl/help/econ/moving-average-trend-estimation.html )尽管如此,但我的问题是我不明白这个"wts"是什么.有人可以解释吗?如果与值的权重有关:在这种情况下,这是无效的.所有值的权重都相同.
So basically, I compute my mean and plot it with a (wrong) moving average. I picked the "wts" value right off the mathworks site, so that is incorrect. (source: www.mathworks.nl/help/econ/moving-average-trend-estimation.html) My problem though, is that I do not understand what this "wts" is. Could anyone explain? If it has something to do with the weights of the values: that is invalid in this case. All values are weighted the same.
如果我这样做完全错误,是否可以寻求帮助?
And if I am doing this entirely wrong, could I get some help with it?
最诚挚的感谢.
推荐答案2016年,MATLAB添加了 movmean 函数,用于计算移动平均值:
In 2016 MATLAB added the movmean function that calculates a moving average:
N = 9; M_moving_average = movmean(M,N)更多推荐
计算移动平均线
发布评论