Path: news.mathworks.com!not-for-mail
From: "Nicholas " <OtherPeopleTookAllTheGoodNames@deleteme.gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Vectorizing data lookback?
Date: Sun, 31 Aug 2008 05:44:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <g9db32$oq6$1@fred.mathworks.com>
Reply-To: "Nicholas " <OtherPeopleTookAllTheGoodNames@deleteme.gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1220161442 25414 172.30.248.38 (31 Aug 2008 05:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 31 Aug 2008 05:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1223050
Xref: news.mathworks.com comp.soft-sys.matlab:488002



I'm trying to develop a function that traverses a vector and
outputs a '1' if the current value is greater than the
previous N-values, '0' if it's not.

Programming this into a "for" loop is trivial:

for ii = n:length(data)

     if data(ii) > max(  data(ii-n:ii-1)  );
          output(ii) = 1;
     else
          output(ii) = 0;

end;

The problem is this approach takes forever and a day to
process. It takes ~2 orders of magnitude longer to run than
similar (but vectorized) functions I've written that operate
on the same exact data. 

I've been trying to vectorize this function as well to
improve the speed, but I can't wrap my brain around it. Any
suggestions?