[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: vectorization
From: |
dbateman |
Subject: |
Re: vectorization |
Date: |
Thu, 17 Jul 2008 01:07:34 -0700 (PDT) |
Ben Abbott wrote:
>
> I took a look at this as well and would have responded earlier but my
> internet went down during a thunderstorm :-(
>
> David, of the three versions you posted only the third ran for me
> without error. While the 3rd version does run, it does not give (what
> I think) is the correct answer :-(
>
Hey the third version worked!! None were tested which is why I had so much
trouble getting it right. However ...
>
> octave:46> A = rand([1,9])
> A =
>
> 0.90785 0.89152 0.74896 0.71078 0.21859 0.26943
> 0.89706 0.63350 0.47987
>
> octave:47> q = newfilter (A, 3)
> q =
>
> 0.89152 0.89152 0.89152 0.26943 0.26943 0.26943
> 0.63350 0.63350 0.63350
>
> Unfortunately, a quick check of the first 3 elements gives a incorrect
> result.
>
> octave:48> mean (A(1:3))
> ans = 0.84944
>
> The repmat approach had not occurred to me. The approach I took was
> to ...
>
> a = mean (reshape(A, [npoints, numel(A)/npoints]));
> q = reshape (ones (npoints, 1) * a, [1, numel(A)]);
>
> Which (I believe) produces the desired result.
>
> octave:49> q = newfilter (A, 3)
> q =
>
> 0.84944 0.84944 0.84944 0.39960 0.39960 0.39960
> 0.67014 0.67014 0.67014
>
The original code indexes back to a copy of the original array elements and
not the mean, so I think my version is correct. Or rather it should have the
same behavior as the original function.
D.
--
View this message in context:
http://www.nabble.com/vectorization-tp18497840p18503619.html
Sent from the Octave - General mailing list archive at Nabble.com.