[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: movavg is different using loop and matrix
From: |
Kai Torben Ohlhus |
Subject: |
Re: movavg is different using loop and matrix |
Date: |
Fri, 6 Sep 2019 09:30:26 +0900 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 |
On 9/6/19 7:33 AM, Dmitri A. Sergatskov wrote:
> On Thu, Sep 5, 2019 at 4:35 PM gigiolone123 via Help list for GNU
> Octave <address@hidden> wrote:
>>
>> hi, look this esample:
>>
>> DevPeriod=16;
>> Equity=magic(100);
>>
>> for hh=1:columns(Equity)
>> ma1=movavg(Equity(:,hh),DevPeriod,DevPeriod,0);
>> endfor
>>
>> ma2=movavg(Equity,DevPeriod,DevPeriod,0);
>>
>>
>> ma1 and ma2 are different from each other
>>
>
> ma1 is a vector (100x1) and ma2 is a matrix (100x100)
>
> Dmitri.
> --
>
>
`ma1` is a vector, because in each for-loop-iteration you are
overwriting `ma1` with another vector. You have 99 pointless
computations and only hh=100 is available after the for-loop.
I think you intend something like:
```
pkg load financial
DevPeriod = 16;
Equity = magic(100);
for hh=1:columns(Equity)
ma1(:,hh) = movavg(Equity(:,hh), DevPeriod, DevPeriod, 0);
endfor
ma2 = movavg (Equity, DevPeriod, DevPeriod, 0);
```
Note that there is an issue with movavg. It cannot process matrices
like for `ma2`. Please see https://savannah.gnu.org/bugs/?56829 for
details.
HTH,
Kai