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 for Programming
 LabTalk Forum
 Sum progressive cell in column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Robinou

France
14 Posts

Posted - 08/22/2018 :  11:03:31 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello Guy,

I would like to sum progressively my data on the row of two columns.

for exemple :

col(1)={1 , 10 , 6, 24};
col(2)[1]=1;

i would like my col(2)={1, 1+10=11, 11+6=17, 17+24=41};
so col(2)={col(2)[1], col(2)[2]=col(2)[1]+col(1)[2], col(2)[3]=col(2)[2]+col(1)[3], etc...};

I use a loop on row in labtalk to do this operation but my column is to long 300000 and origin bug...

col(2)[1]=1;
loop (ii,1, 300000){
int iia=$(ii)+1;
col(2)[$(iia)]=col(2)[$(ii)]+col(1)[$(iia)];
};

How can i do this operation?

Thanks a lot

Hideo Fujii

USA
1582 Posts

Posted - 08/22/2018 :  5:25:52 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Robinou,
The following code should work. In your code, you don't have to (or I say shouldn't) use
$(...) substitution to convert a number to a string. You just keep using ii as a numeric counter.
col(2)[1]=1;
loop (ii,2, 300000){
  col(2)[ii]=col(2)[ii-1]+col(1)[ii];
}
This code runs in 10.3 sec for data with 300,000 rows on my machine.

Hope this is okay.

--Hideo Fujii
OriginLab

P.S. The following 1-line script runs in 0.36 sec. You can try.
col(2)=sum(col(1));

Edited by - Hideo Fujii on 08/22/2018 5:54:58 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