From: Oleg Komarov on
"Wayne King"
> > output = tsmovavg(tsobj, 's',Lag, dim)
> >
> > My vector of prices "Px" is a 2701x1 vector
> > I want to compute the 30 days moving average using:
> >
> > output=tsmovavg(Px,'s',30) and I am receiving an error "lag must be scalar greater than 0 or less than the number of observations". I feel that I am misinterpreting the inputs that I need to use in the function. Any help is appreciated
>
> Sorry, just to add to my last post, if you want to leave Px as a column vector, you should be able to do
>
> output = tsmovavg(Px,'s',30,1); % this way it will work along the column dimension. Otherwise, tsmovavg uses a default dimension of 2 and operates along the row.
>
> Wayne
Doesn't work...
R2009b Win Server 2008 SP2 -64bit
Oleg
From: Oleg Komarov on
"joseph Frank"
Alternatively you can use 'filter', there is an example in the help section on how to calculate moving averages.
Else look for FEX submission with moving,slide, window keywords.

Oleg
From: Loren Shure on
In article <himvsg$rsp$1(a)fred.mathworks.com>,
oleg.komarovRemove.this(a)hotmail.it says...
> "joseph Frank"
> > output = tsmovavg(tsobj, 's',Lag, dim)
> >
> > My vector of prices "Px" is a 2701x1 vector
> > I want to compute the 30 days moving average using:
> >
> > output=tsmovavg(Px,'s',30) and I am receiving an error "lag must be scalar greater than 0 or less than the number of observations". I feel that I am misinterpreting the inputs that I need to use in the function. Any help is appreciated
>
> Line 89 of tsmovavg uses size(tsobject), apparently the size doesn't return the right values:
>
> Px = timeseries(rand(100,1));
> size(Px)
> ans =
> 100 1
> Px = timeseries(rand(1,100));
> size(Px)
> ans =
> 100 1
>
> So i think there is a bug.
> If TMW can confirm...
>
> Oleg
>

The first input to tsmovavg needs to be a timeseries object, not a
regular vector as Px seems to be. You'd need to place/convert Px to the
right class.

--
Loren
http://blogs.mathworks.com/loren
From: joseph Frank on
Thanks guys . it works well now
From: Oleg Komarov on
Loren Shure
> >
> > Px = timeseries(rand(100,1));
> > size(Px)
> > ans =
> > 100 1
> > Px = timeseries(rand(1,100));
> > size(Px)
> > ans =
> > 100 1
> >
> > So i think there is a bug.
> > If TMW can confirm...
> >
> > Oleg
> >
>
> The first input to tsmovavg needs to be a timeseries object, not a
> regular vector as Px seems to be. You'd need to place/convert Px to the
> right class.
>
> --
> Loren
> http://blogs.mathworks.com/loren

But Px is a timeseries obj:

>> Px = timeseries(rand(100,1));
>> isafin(Px,'timeseries')
ans =
1
>> size(Px)
ans =
100 1
>> size(Px.')
ans =
100 1
>> output = tsmovavg(Px, 's',30, 1)
??? Error using ==> tsmovavg>simplema at 238
Lag must be scalar greater than 0 or less than the number of observations.

Error in ==> tsmovavg at 98
vout = simplema(vin, lag, vinVars, observ);

As you can see the size function doesn't recognize more than 1 observations wheter the ts obj is a col vec or a row vec.

Oleg
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Error using of nlinfit function
Next: Relational Operators