Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorize finding upper envelope of vector
Date: Fri, 14 Mar 2008 19:13:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <freinv$94b$1@fred.mathworks.com>
References: <frbrrt$n43$1@fred.mathworks.com> <frcc2m$h6i$1@fred.mathworks.com> <fre6ll$p28$1@fred.mathworks.com> <47daa0e5$0$307$b45e6eb0@senator-bedfellow.mit.edu>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205521983 9355 172.30.248.37 (14 Mar 2008 19:13:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Mar 2008 19:13:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:457305



Arthur G <gorramfreak+news@gmail.com> wrote in message <47daa0e5$0
$307$b45e6eb0@senator-bedfellow.mit.edu>...
> On 2008-03-14 11:47:01 -0400, "Jos " <DELjos@jasenDEL.nl> said:
> > A one-line vectorized cumulative maximum function:
> > 
> >   a = [2 3 4 2 7 5 8] % row vector
> >   CMA = max(triu(toeplitz(a)))
> > 
> >   % -> CMA =  2  3  4  4  7   7   8
> > 
> > which, however(!), will create an intermediate (numel(A).^2)
> > matrix that may cause memory troubles for long vectors.
> 
> Another caveat: the above one-liner won't work if the vector starts 
> with any negative numbers.
-------
  Jos could easily correct for that with:

 CMA = max(toeplitz(repmat(a(1),size(a)),a))

Roger Stafford