Author |
Topic |
|
ChristianJ
Germany
22 Posts |
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;
}
} |
Edited by - ChristianJ on 12/18/2015 06:54:40 AM |
|
SeanMao
China
288 Posts |
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 |
|
|
ChristianJ
Germany
22 Posts |
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
China
288 Posts |
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
Germany
22 Posts |
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
China
288 Posts |
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
Germany
22 Posts |
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
China
288 Posts |
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
|
Edited by - SeanMao on 01/06/2016 03:05:17 AM |
|
|
Castiel
343 Posts |
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.
妾+ 午旦 妹罕妾 妾伊 用仇 妾/ 岫ㄞ
妾京用 仍巨 件 侈 件戶' 甘岫平 /欠 白岫妹
併 艮 岫 奈 白 岫
岫 |
|
|
ChristianJ
Germany
22 Posts |
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 |
|
|
|
Topic |
|