フィルターのクリア

Building a set of simple moving averages using a loop

2 ビュー (過去 30 日間)
Quantopic
Quantopic 2014 年 10 月 7 日
回答済み: Geoff Hayes 2014 年 10 月 7 日
Hi everyvody,
I have to build a set of simple moving averages with different periods; may be that my problem is pretty tricky, but I really do not know how to solve that.
I thought to use the loop for as it follows:
for i = 5:1:30
SMAvector(:,i) = tsmovavg(vector,'s',i,2);
end
but matlab gives an error out as:
Undefined function 'le' for input arguments of type 'cell'.
Can someone help me to find a solution or explain me what does the error mean? Thanks in advance for the help.
  4 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 10 月 7 日
Ok - what have you defined SMAvector to be? Is it a cell array or an empty matrix or..? What happens if you do
SMAvector = zeros(length(vector),30-5+1);
for k = 5:1:30
SMAvector(:,k-5+1) = tsmovavg(vector,'s',k,2);
end
Note that I replaced your i with k since both i and j are used as representations for the imaginary number, and so it is good practice to avoid using either as indices in loops.
Quantopic
Quantopic 2014 年 10 月 7 日
Ok. It seems to work. Thanks a lot Geoff.

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 10 月 7 日
Quantopic verified that the vector variable was of type double. As it was unclear how the SMAvector variables was declared, it was suggested that the following code be tried
SMAvector = zeros(length(vector),30-5+1);
for k = 5:1:30
SMAvector(:,k-5+1) = tsmovavg(vector,'s',k,2);
end
That seemed to work.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by