Path: news.mathworks.com!not-for-mail
From: "Dan Haeg" <haegd@msoe.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorize finding upper envelope of vector
Date: Thu, 13 Mar 2008 22:58:01 +0000 (UTC)
Organization: Milwaukee School of Engineering
Lines: 36
Message-ID: <frcbhp$be0$1@fred.mathworks.com>
References: <frbrrt$n43$1@fred.mathworks.com> <frbvfd$bj4$1@fred.mathworks.com> <frc6au$ehp$1@fred.mathworks.com>
Reply-To: "Dan Haeg" <haegd@msoe.edu>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205449081 11712 172.30.248.35 (13 Mar 2008 22:58:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Mar 2008 22:58:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 475291
Xref: news.mathworks.com comp.soft-sys.matlab:457147



"ashipyard " <andrewshipyard@hush.com> wrote in message
<frc6au$ehp$1@fred.mathworks.com>...
> "Yuri Geshelin" <geshelin@hotmail.com> wrote in message
> <frbvfd$bj4$1@fred.mathworks.com>...
> > ifi = find(diff(a)<0)
> > a(ifi+1)=a(ifi)
> > 
> 
> Thanks for your reply, however this doesn't work how I want.
> Perhaps I didn't explain my problem clearly enough.
> 
> I would like each element to be the highest from all
> previous elements. 
> 
> So, if if 
> 
> a=[1 2 3 4 3 2 3 5]
> 
> then I would like this to become
> 
> [1 2 3 4 4 4 4 5].
> 
> Using the code you provided, this would yield
> 
> [1 2 3 4 4 3 3 5] which isn't what I after.

this may run fast enough.

a=[1 2 3 4 3 2 3 5]
ifi = find(diff(a)<0)
while ~isempty(ifi)
    a(ifi+1)=a(ifi)
    ifi = find(diff(a)<0)
end