计算移动平均线

编程入门 行业动态 更新时间:2024-10-27 06:25:39
本文介绍了计算移动平均线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在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)

更多推荐

计算移动平均线

本文发布于:2023-10-15 02:26:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492977.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:平均

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!