用tsmovavg求移动平均,有时候会出错,不明白为什么。公式照着是一样的,比如:a=tsmovavg(AD,'e',13,1),AD是一个向量。matlab总是报错Lag must be scalar greater than 0 or less than the number of observations.
求问tsmovavg的具体用法,举一些例子,求简单移动平均和指数移动平均
matlab中tsmovavg的具体用法 格式如下:
output = tsmovavg(tsobj, 's', lag) (Simple)
output = tsmovavg(tsobj, 'e', timeperiod) (Exponential)
output = tsmovavg(tsobj, 't', numperiod) (Triangular)
output = tsmovavg(tsobj, 'w', weights) (Weighted)
output = tsmovavg(tsobj, 'm', numperiod) (Modified)
给你一个实例:
load disney.mat
weekly = toweekly(dis);
dates = (weekly.dates);
price = fts2mat(weekly.CLOSE);
window_size = 12;
simple = tsmovavg(price,'s',window_size,1);
exp = tsmovavg(price,'e',window_size,1);
tri = tsmovavg(price,'t',window_size,1);
semi_gaussian = [0.026 0.045 0.071 0.1 0.12 0.138];
semi_gaussian = [semi_gaussian fliplr(semi_gaussian)];
weighted = tsmovavg(price,'w',semi_gaussian,1);
modif = tsmovavg(price,'m',window_size,1);
plot(dates,price,dates,simple,dates,exp,dates,tri,dates,weighted,dates,modif)
datetick
legend('Stock Price','Simple','Exponential','Triangular','Weighted','Modified','Location','NorthWest')
title('Disney Weekly Price & Moving Averages')
运行结果
matlab中tsmovavg的具体用法
output = tsmovavg(tsobj, 's', lag) (Simple)output = tsmovavg(tsobj, 'e', timeperiod) (Exponential)output = tsmovavg(tsobj, 't', numperiod) (Triangular)output = tsmovavg(tsobj, 'w', weights) (Weighted)output = tsmovavg(tsobj, 'm', numperiod) (Modified)...