Path: news.mathworks.com!not-for-mail
From: "GG " <ggkmath@comcast.net>
Newsgroups: comp.soft-sys.matlab
Subject: help vectorizing a FOR loop
Date: Thu, 4 Sep 2008 14:51:01 +0000 (UTC)
Organization: Jittertime Consulting
Lines: 20
Message-ID: <g9oskl$st1$1@fred.mathworks.com>
Reply-To: "GG " <ggkmath@comcast.net>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1220539861 29601 172.30.248.35 (4 Sep 2008 14:51:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Sep 2008 14:51:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1432308
Xref: news.mathworks.com comp.soft-sys.matlab:488596



Hi Experts, 

I'm hoping someone can help me vectorize the following 
code. The tricky part is that bin_width is a function of 
the loop-index i.

for i = 1:1:10000
  smoothline(i) = mean(data(i-bin_width(i)/2:i+bin_width
(i)/2)
end

This code is just a sliding-window average to smooth-out a 
noisy data array. The smoothed line is created at each 
data point by looking at bin_width(i)/2 datapoints ahead 
and bin_width(i)/2 datapoints behind, and taking the mean 
of all this data. Then it steps to the next datapoint and 
repeats with a new bin_width(i) value.

Thanks in advance, -GG