gpt4 book ai didi

matlab - 计算移动平均线

转载 作者:太空宇宙 更新时间:2023-11-03 20:11:03 24 4
gpt4 key购买 nike

我需要在 for 循环中计算数据系列的移动平均值。我必须获得 N=9 天的移动平均线。我正在计算的数组是 4 个系列的 365 个值 (M),它们本身是另一组数据的平均值。我想在一个图中用移动平均值绘制数据的平均值。

我在谷歌上搜索了一些关于移动平均线和“conv”命令的信息,发现了一些我尝试在我的代码中实现的东西。:

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”值,所以这是不正确的。 (来源:http://www.mathworks.nl/help/econ/moving-average-trend-estimation.html)但我的问题是,我不明白这个“wts”是什么。谁能解释一下?如果它与值的权重有关:在这种情况下无效。所有值的权重都相同。

如果我做的完全错了,我能得到一些帮助吗?

最诚挚的谢意。

最佳答案

还有两种选择:

1) filter

来自文档:

You can use filter to find a running average without using a for loop. This example finds the running average of a 16-element vector, using a window size of 5.

data = [1:0.2:4]'; %'
windowSize = 5;
filter(ones(1,windowSize)/windowSize,1,data)

2) smooth作为曲线拟合工具箱的一部分(在大多数情况下可用)

来自文档:

yy = smooth(y) smooths the data in the column vector y using a moving average filter. Results are returned in the column vector yy. The default span for the moving average is 5.

%// Create noisy data with outliers:

x = 15*rand(150,1);
y = sin(x) + 0.5*(rand(size(x))-0.5);
y(ceil(length(x)*rand(2,1))) = 3;

%// Smooth the data using the loess and rloess methods with a span of 10%:

yy1 = smooth(x,y,0.1,'loess');
yy2 = smooth(x,y,0.1,'rloess');

关于matlab - 计算移动平均线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26002818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com