Path: news.mathworks.com!not-for-mail
From: "Titus" <titus.edelhofer@mathworks.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorizing data lookback?
Date: Mon, 1 Sep 2008 16:03:21 +0200
Organization: The MathWorks, Inc.
Lines: 37
Message-ID: <g9gsna$qll$1@fred.mathworks.com>
References: <g9db32$oq6$1@fred.mathworks.com>
NNTP-Posting-Host: de-edelhoft-x.ac.mathworks.de
X-Trace: fred.mathworks.com 1220277802 27317 172.16.75.150 (1 Sep 2008 14:03:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 1 Sep 2008 14:03:22 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
Xref: news.mathworks.com comp.soft-sys.matlab:488105




"Nicholas " <OtherPeopleTookAllTheGoodNames@deleteme.gmail.com> schrieb im 
Newsbeitrag news:g9db32$oq6$1@fred.mathworks.com...
> 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?

Hi,

without really answering the question: did you preallocate your output? 
Something like
output = zeros(size(data));
before entering the loop?

Titus