help-octave
[Top][All Lists]
Advanced

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

Re: vectorization


From: Ben Abbott
Subject: Re: vectorization
Date: Thu, 17 Jul 2008 10:13:37 -0400


On Jul 17, 2008, at 4:07 AM, dbateman wrote:


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.

opps ... of course, you are correct. My mind has a nasty habit of "filtering" text as I read it. I'd missed that he was extracting the value closest to the mean.

Ben



reply via email to

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