Building a set of simple moving averages using a loop
Show older comments
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 Comments
Geoff Hayes
on 7 Oct 2014
Edited: Geoff Hayes
on 7 Oct 2014
I think that the error refers to the less than or equal operator not being defined for inputs of type cell. What is the data type on vector? In the Command Window type
class(vector)
Does it show cell as the answer?
Looking at tsmovavg, the first input can only be a financial time-series object, or a vector (or matrix) of observations (so not a cell array).
Geoff Hayes
on 7 Oct 2014
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
on 7 Oct 2014
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!