Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find vector r<=p (p: a given vector)
Date: Mon, 19 Jan 2009 22:45:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 18
Message-ID: <gl2vpg$9ts$1@fred.mathworks.com>
References: <gf2ppf$q6l$1@fred.mathworks.com> <ggcs55$aiv$1@fred.mathworks.com> <ggf7ro$fal$1@fred.mathworks.com> <gl26qm$8p1$1@fred.mathworks.com> <gl2tva$2ng$1@fred.mathworks.com> <gl2v1f$cmg$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1232405104 10172 172.30.248.38 (19 Jan 2009 22:45:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 19 Jan 2009 22:45:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1582760
Xref: news.mathworks.com comp.soft-sys.matlab:512575


"Matt Fig" <spamanon@yahoo.com> wrote in message <gl2v1f$cmg$1@fred.mathworks.com>...
> Oh, hello.  I didn't see this old one had been resurrected!
> 
> Basically my approach was to build the index for cumsum (a technique I have seen many others use).  If you run the code without the semicolon on the line that creates the drops for y you can see the pattern.  To use this method you need to understand how cumsum works, and look for this type of pattern.  Since the result from cumsum is off by one, I just subtracted one from the vector before storing it in R.  
> 
> The main speed advantage, as far as loop is concerned, is pre-allocating the matrix R and y.  Also, Matlab's JIT likes all variables to stay the same size and type during a loop, so that is why I set y to zero at the end of each iteration.  
> 
> Hope that clears things up some :)
> 
> 
> 
> 
> e!R](z882.'y%$8.{"X/F%}})&8&("?(} y-8yy(-y}(z{q'8(y8?-)y!8!

Thank you, Matt. hmm.. this cumsum function really confuses me, I know technically what it does, it culmulatively sums the values up column-wise, but why do this? I still don't see the big picture.. but I think more about it tomorrow.  In case you still have patience, what's the purpose of these "drops" ?  

Oriole