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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 If-condition to generate col out of another col
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Shock

USA
3 Posts

Posted - 07/10/2014 :  1:28:23 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello everyone!

My problem is the following. I'd like to have a script that is excecuted in Col(B) and checks the data of Col(A). If the value of Col(A) is < 0, than there should be a 0 in Col(B). If the value of Col(A) is not < 0, than there should be this value in Col(B).

I've tried it like

if (Col(A)[i] < 0){
Col(B)[i] = 0
}
[else Col(B)[i]=Col(A)[i];]

but it won't work.

It'd be great to get some help of you guys!

greg

USA
1378 Posts

Posted - 07/10/2014 :  3:39:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Your expression would work if you looped over all rows in column A, but as written it will only work for whatever the current value of "i" is (and will fail if "i" does not exist or has a zero or negative value.

You can use the Ternary Operator to achieve what you want in either the Script Window or in Set Column Values:

col(B) = col(A) < 0 ? 0 : col(A)

In Set Column Values for column B you only need the right side:

col(A) < 0 ? 0 : col(A)

Think of "?" as THEN and ":" as ELSE.
Go to Top of Page

Shock

USA
3 Posts

Posted - 07/11/2014 :  10:25:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much, works as intended!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000