help-octave
[Top][All Lists]
Advanced

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

vectorization


From: Josh Bell
Subject: vectorization
Date: Wed, 16 Jul 2008 14:03:19 -0800

Hi, this is my first time trying to ask a question here, so i hope this makes 
sense.   What I am trying to do involves vectorizing an M-file that I wrote.  I 
have a long data file, which is basically just a string of numbers.  It is 
meant to represent a certain signal embedded in noise.  What I want to do is 
take a certain piece of that data file (say, the first 10 data points, for 
instance) and replace all of the data points within that window with the value 
that is nearest to the mean of that window.  In other words, I would take these 
10 points from the input (which is an array with 1 column and approximately 
19000 rows), and place them in a separate array (the output array).  I would 
then find the value within the output array that was closest to the mean of 
that chunk of data, and replace all 10 values with this number.  I would then 
do the same with points 21-30, 31-40, etc.  I have already successfully done 
this with a 'for' loop, but it runs slower than cold molasses.  I will include 
that code below.

function q = newfilter1 (A, npoints)

%A is the input array

for n = npoints+1:length(A)-npoints

a = A(n-npoints:n+npoints);

 b(1,1:length(a)) = a';

 b(2,1:length(a)) = mean(a);

[avg, Ia] = min(abs(diff(b)));

q(n-npoints:n+npoints) = b(1,Ia);

end
endfunction

any help would be greatly appreciated.  Thanks!
_________________________________________________________________
Time for vacation? WIN what you need- enter now!
http://www.gowindowslive.com/summergiveaway/?ocid=tag_jlyhm


reply via email to

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