The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 Sum of Rows

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
cyndi.y.ri Posted - 01/11/2006 : 1:21:33 PM
Origin Version: OriginPro 6.1
Operating System: Windows XP

Please help. Is there a way to simplify this? I think maybe a loop would work but I am not a programmer and cannot figure this out.

for(i=4;i<9;i+1){col(TOTAL)[4]=col(FLOW)[4]+col(FLOW)[5]+col(FLOW)[6]+col(FLOW)[7]+col(FLOW)}
for(i=9;i<14;i+1){col(TOTAL)[9]=col(FLOW)[9]+col(FLOW)[10]+col(FLOW)[11]+col(FLOW)[12]+col(FLOW)[13]}
for(i=14;i<19;i+1){col(TOTAL)[14]=col(FLOW)[14]+col(FLOW)[15]+col(FLOW)[16]+col(FLOW)[17]+col(FLOW)[18]}

Thanks for any help!

Edited by - cyndi.y.ri on 01/11/2006 5:00:51 PM
3   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 01/11/2006 : 5:48:11 PM
If you intend to repeat the col(TOTAL)[j] calculation for j=19,24,29,... then vector math will be much more efficient. The ave(dataset,n) function returns a dataset containing the averages of dataset taken n rows at a time...

ii=4; // starting row
jj=5; // group size
set col(FLOW) -b ii; // hide first ii-1 rows in col(FLOW)
tmp=ave(col(FLOW),jj); // average visible rows jj at a time
tmp *= jj; // multiply by jj to get sums
get tmp -e npt; // npt = # of results
for(i=0;i<npt;i++) {
col(TOTAL)[i*jj+ii]=tmp[i+1]; // transfer results to col(TOTAL)
};
del tmp; // delete temporary dataset
set col(FLOW) -b 1; // show all rows in col(FLOW)

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/11/2006 5:49:29 PM
cyndi.y.ri Posted - 01/11/2006 : 5:02:27 PM
THANKS!!!! I will give this a try.

Mike Buess Posted - 01/11/2006 : 4:58:39 PM
Hi Cyndi,

Since the index i doesn't appear inside { } your script merely repeats the summation col(TOTAL)[4]=col(FLOW)[4]+col(FLOW)[5]+col(FLOW)[6]+col(FLOW)[7] four times. I think you're looking for a shorter way to perform that summation once. a+=b is short-hand notation for a=a+b so this is one possibility...

col(TOTAL)[4] = 0;
for(i=4;i<8;i++) {col(TOTAL)[4] += col(FLOW)[i]};

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/11/2006 5:02:46 PM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000