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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Vectors and Cumulative Summation

amaurer
1-Visitor

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!!

ACCEPTED SOLUTION

Accepted Solutions

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

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

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

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

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

Announcements

Top Tags