summing over subscript ranges
-
- Junior Member
- Posts: 14
- Joined: Tue Mar 25, 2003 9:25 am
summing over subscript ranges
Summing over the entire subscript range is easy using sum(!). My question is: Is there a way to sum over the first (or last) n elements in an m element range (m>n)?:(
-
- Super Administrator
- Posts: 4609
- Joined: Wed Mar 05, 2003 3:10 am
-
- Junior Member
- Posts: 14
- Joined: Tue Mar 25, 2003 9:25 am
-
- Junior Member
- Posts: 14
- Joined: Tue Mar 25, 2003 9:25 am
-
- Junior Member
- Posts: 14
- Joined: Tue Mar 25, 2003 9:25 am
Re: summing over subscript ranges
If the number of elements you want to sum is fixed, it's more efficient to use a subrange, e.g.
sub : (s1-s10)
subr : (s1-s6)
myvar = SUM( myothervar[subr!] )
sums over the first 6 elements of the 10-element range, without having to iterate over the elements s7-s10 that aren't needed.
The VECTOR SELECT function is also often useful when you want to sum over sparse subsets of a range.
Tom
sub : (s1-s10)
subr : (s1-s6)
myvar = SUM( myothervar[subr!] )
sums over the first 6 elements of the 10-element range, without having to iterate over the elements s7-s10 that aren't needed.
The VECTOR SELECT function is also often useful when you want to sum over sparse subsets of a range.
Tom
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/