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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Sum of Rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cyndi.y.ri

USA
11 Posts

Posted - 01/11/2006 :  1:21:33 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

Mike Buess

USA
3037 Posts

Posted - 01/11/2006 :  4:58:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cyndi.y.ri

USA
11 Posts

Posted - 01/11/2006 :  5:02:27 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
THANKS!!!! I will give this a try.

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/11/2006 :  5:48:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000