cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Vectors and Cumulative Summation

amaurer
1-Newbie

Vectors and Cumulative Summation

Hello everyone. I need help programming a loop that can calculate a cumulative running sum given a vector of values. For example, if cell(1,1) = 10 and cell(1,2) = 2, then the cumulative sum would be 12 and if cell(1,3)=4, then the cumulative sum would be cell(1,1)+cell(1,2)+cell(1,3)=16. I need to have a matrix that shows the incremental values in Col(1) and the cumulative sums in Col(2). I've attached a worksheet that resembles the type of data and loop format that I need to build.

Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
MikeArmstrong
5-Regular Member
(To:amaurer)

Something like the attached?

Mike

http://communities.ptc.com/servlet/JiveServlet/showImage/2-149416-2532/bar_anim.gif

View solution in original post

6 REPLIES 6
MikeArmstrong
5-Regular Member
(To:amaurer)

Something like the attached?

Mike

http://communities.ptc.com/servlet/JiveServlet/showImage/2-149416-2532/bar_anim.gif

Perfect. Thanks for your help, Mike. I appreciate the rapid responses!!!!

Anne

MikeArmstrong
5-Regular Member
(To:amaurer)

Another way

Unk424.gif

Mike

Mike Armstrong wrote:

Another way

Unk424.gif

This is probably the better way - using the summation operator results in redundant calculations. I've attached a sheet showing the difference in times and also the almost insignificant difference that pre-allocating the result vector makes.

Stuart

MikeArmstrong
5-Regular Member
(To:StuartBruff)

To be honest that is way I would have proposed, but when looking for the function I came across the summation operator first.

I've attached a sheet showing the difference in times and also the almost insignificant difference that pre-allocating the result vector makes.

We have been across this before. Wayne, Richard and myself had a lengthy discussion about calculation speed and the methods one can undertake to improve the speed. Pre-allocating an array only seemed to offer significant benefit on large matrices.

Mike

http://communities.ptc.com/servlet/JiveServlet/showImage/2-149416-2532/bar_anim.gif

MikeArmstrong
5-Regular Member
(To:amaurer)

Thanks for your help, Mike. I appreciate the rapid responses!!!!

No problem, I was just about to log off aswel.

Mike

http://communities.ptc.com/servlet/JiveServlet/showImage/2-149416-2532/bar_anim.gif

Top Tags