The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums  Origin Forum for Programming  LabTalk Forum  Autofill Column with Last Known Value New Topic  Reply to Topic  Printer Friendly
Author  Topic

USA
Posts

 Posted - 04/02/2012 :  6:03:00 PM Is there a Labtalk routine or an X-function to fill cells with the last known value? For example,col(B)={0 -- -- -- -- -- -- -- 1 -- -- -- -- 12 -- -- 0 --}.I would like to process so col(B)={0 0 0 0 0 0 0 0 1 1 1 1 1 12 12 12 0 0}.I can have hundreds of thousands of missing values to fill so I'd prefer not to resort to nested loops, which can be quite slow.DrBobShepherdOrigin Ver. and Service Release (Select Help-->About Origin):OriginPro 8.6.0 Operating System:Window XP

USA
992 Posts

 Posted - 04/04/2012 :  4:18:34 PM Hi Drbobshepherd,How about the following formula in the Set Column Values tool?col(B)[i]==1/0?col(B)[i-1]:col(B)[i]--Hideo FujiiOriginLab

USA
Posts

 Posted - 05/02/2012 :  10:34:53 AM Hideo,Thanks, your command works perfectly. I see that it is basically an if statement:if(col(B)[i]==NaN) col(B)[i]=col(B)[i-1];but I am not familiar with the language. Do you have a reference I could use to learn it?DrBobShepherd

France
106 Posts

 Posted - 05/02/2012 :  11:04:04 AM It is more an if - else statement, used in variable assignement. General syntax is:variable=condition?value1:value2;--> variable will be assigned to value1 if condition is true, or value2 if condition if false.if your case, full corresponding command is:col(B)[i]=col(B)[i]==1/0?col(B)[i-1]:col(B)[i];which mean:if col(b)[i] is NaN, put col(b)[i-1] into col(b)[i]else put col(b)[i] into col(b)[i]Search for "conditionnal operator" into labtalk help

France
106 Posts

 Posted - 05/02/2012 :  11:11:05 AM note that it can also be used for vector assignement.For example:range r1=1, r2=2;r1=uniform(100000);r2=r1>0.5?1:0;

USA
Posts

 Posted - 05/02/2012 :  2:29:57 PM Couturier,I found the reference in Help/Programming/Main/Operators/Conditional. Hard to believe I have been programming for decades without ever being aware of this useful operator. It just fell through the cracks. This proves I don't know everything, but with your help, I am closer.Dr. Bob

USA
992 Posts

 Posted - 05/03/2012 :  11:03:33 AM Hi Couturier,I also want to say thank you. That vector expression is a surprising rediscovery for me, too.--HideoP.S. For my curiosity, I have compared the speed of Couturier's vector and If statement. ```//////////////////////////// sec; range r1=1, r2=2; r1=uniform(100000); r2=r1>0.5?1:0; sec -e time; type -a Vector: \$(time) sec; // window -t wks; sec; range r1=1, r2=2; r1=uniform(100000); for(ii=1; ii<=100000; ii++) { if(r1[ii]>0.5) r2[ii]=1; else r2[ii]=0; } sec -e time; type -a IF: \$(time) sec; Vector: 0.188 sec IF: 13.338 sec ```So, the conditional operator for vectors is 70(=13.34/0.19) times faster! Edited by - Hideo Fujii on 05/03/2012 11:38:44 AM
Topic
 New Topic  Reply to Topic  Printer Friendly Jump To: Select Forum Origin Forum       Origin Viewer and Orglab Forum       Origin Forum Origin Forum for Programming       LabTalk Forum       Forum for Origin C       Forum for Automation Server/COM and LabVIEW Japanese Origin Forum       Origin日本語フォーラム (Japanese Origin Forum) Origin on Linux       The Origin on Linux Forum Private Forums       Distributor Forum  -------------------- Home Active Topics Frequently Asked Questions Member Information Search Page
 The Origin Forum © 2008 Originlab Corporation