Path: news.mathworks.com!not-for-mail
From: "Nicholas " <OtherPeopleTookAllTheGoodNames@deleteme.gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorizing data lookback?
Date: Wed, 3 Sep 2008 15:28:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <g9mae2$7g0$1@fred.mathworks.com>
References: <g9db32$oq6$1@fred.mathworks.com> <d3e32ef1-ba0b-4789-a5b1-220c64ee361c@25g2000hsx.googlegroups.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 1220455682 7680 172.30.248.38 (3 Sep 2008 15:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 3 Sep 2008 15:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1223050
Xref: news.mathworks.com comp.soft-sys.matlab:488419



heiko_marx@hotmail.com wrote in message
<d3e32ef1-ba0b-4789-a5b1-220c64ee361c@25g2000hsx.googlegroups.com>...

> Hi.
> 
> I found that avoiding the max function in each loop
reduces the time
> by a good amount.
> 
> >> tic; for ii =3D n:length(data), if data(ii) >
max(data(1:ii-1)); output(=
> ii) =3D 1; else output(ii) =3D 0;end, end, toc
> Elapsed time is 0.010647 seconds.
> >> tic; m =3D max(data(1:n-1)); for ii =3D n:length(data),
if data(ii) > m,=
>  output2(ii) =3D 1; m =3D data(ii); else output2(ii) =3D
0;end, end, toc
> Elapsed time is 0.001932 seconds.
> >> isequal(output, output2)
> ans =3D
>      1
> 
> The times refer to a data set of 1000 random values, aand
are of
> course machine-dependent.
> 
> Hope this helps,
> Heiko


Heiko-

If I'm reading your code correctly, it wouldn't work for my
application. It computes a single max value for the vector
m, and compares this value to data on a bar by bar basis.

In my application, I need to compare each data point to the
previous 'n' data points where n < length(data). In other
words, I have vectors that have ~750K data points. If I
specify n = 25, the function would take data point 26 from
that vector and see if it was greater than the previous 25
data points (1-25). It would then move to data point 27 and
see if was greater than the previous 25 data points (2-26).
Then it moves to point 28 and compares it to point 3-27...