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 for Programming
 LabTalk Forum
 Sum progressive cell in column

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
Robinou Posted - 08/22/2018 : 11:03:31 AM
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
1   L A T E S T    R E P L I E S    (Newest First)
Hideo Fujii Posted - 08/22/2018 : 5:25:52 PM
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));

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