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
 Fastening For Loop

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
ChristianJ Posted - 12/18/2015 : 06:53:52 AM
Origin Ver. OriginPro 2015G (64-bit) Sr2
Operating System: Windows7


Hello Experts
again I'm begging for help.
To set column values, I'm using a LabTalk script out of the set-values-dialog. It summarizes the values of one column row by row, and sets it to zero if another column fits a specific value. It's functioning correct, but it is really, really, really slow. By the way: There are about just 100000 rows to loop.

My Questions are:
a) Is there a way to make loops faster (using Labtalk)?
b) Is there a way to write the code in origin C an use it in the set-values-dialog?
c) Do you have some other useful hints?

Here is my code:
string str1$ = __lastwks$; 

range r1 = [str1$]6!11;
range r2 = [str1$]6!5;
range r3 = [str1$]6!10;

r1 = {1: r2.GetSize()};
r1 = 0;

for (ii=2; ii<r1.GetSize(); ii++)
{
    if(r3[ii] == 0)
    {
        r1[ii] = r1[ii-1] + r2[ii];
    }

    if(r3[ii] == 1)
    {
        r1[ii] = 0;
    } 
}
9   L A T E S T    R E P L I E S    (Newest First)
ChristianJ Posted - 01/21/2016 : 03:52:07 AM
Hi
even if I don't understand what LOCK means, thanks for your suggestion, Castiel. I will try using Python!
Meanwhile I stopped insisting on using LabTalk. Using OriginC for this solved my problem. Thanks for your patience, Sean
Castiel Posted - 01/10/2016 : 12:38:56 AM
quote:
Originally posted by ChristianJ

Hi Sean
thank you for your reply. But this doesn't answers my question. I would like to know, if there is a way to speed up Labtalk For-Loops on columns just using Labtalk.

Apologies when my english caused irritations here (it's not my first language ).

btw: Happy new year!



If LOCK is not a must-have, Python you may try.

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
SeanMao Posted - 01/06/2016 : 03:04:42 AM
Hi,

If you insist on using for loop to run command row by row, I guess there is no other more efficient way to speed the calculation up.

If you only want to embed the code I give you earlier to allow it to be run automatically during import via script, you can replace your whole for loop as following command:

csetvalue col:=col("Date") formula:="col("Date")[i]==0/0?(i==1?col("Date")[i]:col("Date")[i-1]):col("Date")[i]";

col("Date") = Col("Date") + col("Time");

wks.col1.SetFormat(4, 22, yyyy'.'MM'.'dd H'.'mm'.'ss'.'####');

Regards!

Sean


ChristianJ Posted - 01/05/2016 : 11:08:42 AM
Hi Sean
thank you for your reply. But this doesn't answers my question. I would like to know, if there is a way to speed up Labtalk For-Loops on columns just using Labtalk.

Apologies when my english caused irritations here (it's not my first language ).

btw: Happy new year!
SeanMao Posted - 12/22/2015 : 10:09:30 PM
Hi,

You can use the formula below to set column value for column Date to fill the rest of cells with corresponding dates:


col("Date")[i]==0/0?(i==1?col("Date")[i]:col("Date")[i-1]):col("Date")[i]


where 0/0 = NA (missing value)

After that, you need to simply set col("Time") = col("Date")+col("Time") to combine date and time.

Regards!

Sean

ChristianJ Posted - 12/22/2015 : 02:37:54 AM
Hi Sean
thanks a lot! It is working just fine now. Nice to know that missing indices can cause problems here. The formula is even working without setting initial values. This can save about 10 minutes per datatable for me

OK, actually I didn't need to use LabTalk here. But as I mentioned before, I want to speed up other For-Loops as well. How can I do this? Here is an example:

My data comes as csv file, where the first column is filled by the datestamp, the second column by the timestamp and every following column by actual data. The date stamp is only set for rows, where the date increments. As you can see, I have to add the last valid date to the time for each row.

After your last advice, I would know how to do this using formulas. I think I could even automate this within the importscript. But I would really like to know how For-Loops could be made faster.
SeanMao Posted - 12/21/2015 : 8:58:20 PM
Hi,

Can you try the script in the pic below, assuming you already made the initial values in column C as 0 before calculations:



It is better to use row index "i" if cell level manipulation is involved.

Regards!

Sean
ChristianJ Posted - 12/21/2015 : 03:05:52 AM
Hi Sean
thank you very much for your response. Unfortunately I described my problem not clear enough... Please see the (hopefully self-explanatory) picture below:



In this case I want to count occurrences of a specific event. But I have other problems where I have to summarize non-boolean values in a similar way, for which the formula/script should work too.
I think the main problem is, that the formula refers to values from the column which it is calculating (see the underlined area in the following script). I tried this after your suggestion:

Col(D)=
i==1?(0):(col(b)==0?(col(d)[i-1]+col(a)):(0))

But it is not working (except the first row and every row where end of period is true)... Do you have any other suggestion?

Thanks in advance!
C
SeanMao Posted - 12/19/2015 : 05:24:25 AM
Hi,

You can try to use Origin's nested conditional command as shown below:



You can manipulate the command to fit your own case.

Regards!

Sean

OriginLab Tech. Service

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