vectorization
David Bateman
David.Bateman at motorola.com
Wed Jul 16 18:01:36 CDT 2008
David Bateman wrote:
> The final reshape should use size(a) and not size(A).. Thus the code
>
> function q = newfilter1 (A, npoints)
>
> % assumes A is a muliple of npoints long
> a = reshape (A, npoints, numel(A) / npoints);
> q = reshape (repmat (min (abs(A - repmat(mean (A, 1), npoints, 1)),
> 1), npoints, 1), size (a));
>
> endfunction
>
> should be used instead. Untested as is the previous code.
>
> D.
>
Sorry take 3.
function q = newfilter (A, npoints)
% assumes A is a muliple of npoints long
a = reshape (A, npoints, numel(A) / npoints);
[dum, idx] = min (abs(a - repmat(mean (a, 1), npoints, 1)), [], 1)
q = reshape (repmat (a(idx + [0 : numel(A) / npoints - 1] * ...
npoints), npoints, 1), size (A));
endfunction
Bit hard to test the code at the moment due to lack of a copy of Octave,
which explains the number of attempts to get it right
D.
More information about the Help-octave
mailing list