help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function movavg dont work with matrix


From: Kai Torben Ohlhus
Subject: Re: function movavg dont work with matrix
Date: Wed, 28 Aug 2019 10:39:41 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

On 8/28/19 12:19 AM, LucaLuca via Help list for GNU Octave wrote:
> Equity=magic(4);
> AvgEquity=2;
> 
>  movAverage2=movavg(Equity,AvgEquity,AvgEquity,0); 
> 
> 
> Equity =
> 
>   16    2    3   13
>     5   11   10    8
>     9    7    6   12
>     4   14   15    1
> 
> movAverage =
>      OK          Not OK    Not OK  Not OK
>    16.0000    2.0000    3.0000   13.0000
>    10.5000   11.0000   10.0000    8.0000
>     7.0000    7.0000    6.0000     12.0000
>     6.5000   14.0000   15.0000    1.0000
> 
> the average of column 1 is correct ... while in the other columns they are
> copied from the original maatrice
> 
> 

The function "movavg" from the financial package is only capable of
treating vectors.  This I conclude from inspecting the current
implementation of about 60 lines of code

   pkg load financial
   edit movavg

Compared to the current Matlab version of "movavg" [1], the
implementation of the financial package is rather simple and might have
been compatible back in 2008 when it was written.

A workaround might be the code for "movAverage3" inspired by [2]:

  pkg load financial

  Equity=magic(4);
  AvgEquity=2;

  movAverage2=movavg(Equity,AvgEquity,AvgEquity,0)

  movAverage3=cell2mat ( ...
    arrayfun (@(i) movavg (Equity(:,i), AvgEquity, AvgEquity, 0), ...
              1:size(Equity,2), 'UniformOutput', false))

I added the package maintainer to this discussion and suggest that at
least the documentation should be updated, that only vectors can be treated.

It would be nice, if you can open a bug report about this [2].  You are
very welcome to improve that function with your knowledge, if you like.

Best regards,
Kai


[1] https://www.mathworks.com/help/finance/movavg.html
[2]
https://www.mathworks.com/matlabcentral/answers/417932-apply-function-to-each-column-of-matrix-for-all-columns-without-for-loop
[3] https://savannah.gnu.org/bugs/?func=additem&group=octave



reply via email to

[Prev in Thread] Current Thread [Next in Thread]