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 23:04:01 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 19
Message-ID: <gl30t1$g9t$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> <gl2vpg$9ts$1@fred.mathworks.com>
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 1232406241 16701 172.30.248.37 (19 Jan 2009 23:04:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 19 Jan 2009 23:04:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:512578



> 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" ?  


The drops are to reset the cumulative sum.  If we didn't put in drops, we couldn't get the repeating pattern out of cumsum.  For example, cumsum this guy:

x = [1 0 0 1 0 0 -1 0 0 1 0 0 ]

See the pattern?  We couldn't get the pattern to go 111222 then back to 111222 without adding a negative number (or drop) for the cumsum. 

As far as the big picture, it is simply seeing the pattern of the final return from Bruno's code (I think it was) then trying to get that with cumsum.  Note that we could have put the cumsum outside the loop, just store the y's in their correct columns in R, then cumsum R after the loop.  I don't know if this would really make that much difference time wise. 


As with any piece of confusing or murky code, just spend some time looking at the output of various stages, you'll get it... 




0$!$+t+|;Bh1|!0}`;|1(|;|;+B,+,;~%!$0}[2|);(;*';5~+#I)U+|*%!