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
 Autofill Column with Last Known Value

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
Drbobshepherd 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.

DrBobShepherd


Origin Ver. and Service Release (Select Help-->About Origin):OriginPro 8.6.0
Operating System:Window XP
6   L A T E S T    R E P L I E S    (Newest First)
Hideo Fujii 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.

--Hideo

P.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!
Drbobshepherd 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
couturier 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;
couturier 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
Drbobshepherd 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
Hideo Fujii 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 Fujii
OriginLab

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