Path: news.mathworks.com!newsfeed-00.mathworks.com!panix!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail
From: Arthur G <gorramfreak+news@gmail.com>
Newsgroups: comp.soft-sys.matlab
Date: Fri, 14 Mar 2008 11:59:33 -0400
Message-ID: <47daa0e5$0$307$b45e6eb0@senator-bedfellow.mit.edu>
References: <frbrrt$n43$1@fred.mathworks.com> <frcc2m$h6i$1@fred.mathworks.com> <fre6ll$p28$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Subject: Re: vectorize finding upper envelope of vector
User-Agent: Unison/1.8
Lines: 14
NNTP-Posting-Host: WHITAKER-THREE-NINETY-THREE.MIT.EDU
X-Trace: 1205510373 senator-bedfellow.mit.edu 307 18.56.6.138
Xref: news.mathworks.com comp.soft-sys.matlab:457264



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.