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
 Origin Forum
 Does origin have a "IF function"
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

spstills23

1 Posts

Posted - 05/09/2017 :  3:59:34 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.2017 and Service Release (Select Help-->About Origin):
Operating System:

Does OriginLab 2017 have a "IF" function like excel does? I have a value in Column (U)[1] and I want to create a conditional sequence for the cell so that if the value in that cell was in 3 different numerical ranges provided it would give me the text of (within first range) "Mild", (2nd range) "Moderate" or (third range) "Significant". Is this possible in Origin?

Thanks for the help!

jdf726

78 Posts

Posted - 05/09/2017 :  6:38:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can do it using boolean logic /comparison in labtalk
(You can improve the logic and use variables to store the thresholds but this is the gist).

col(1) = {1:10}; //Fill first column with numbers
for (ii=1;ii<11;ii++) //loop over rows
{
range rr = !1[ii]; //get cell data
if ((rr>=1)&&(rr<=4)) cell(ii,2) = "Low";
if ((rr>=4)&&(rr<=7)) cell(ii,2) = "Medium";
if ((rr>=7)&&(rr<=11)) cell(ii,2) = "High";
};

Gives...

1 Low
2 Low
3 Low
4 Medium
5 Medium
6 Medium
7 High
8 High
9 High
10 High


I had to use 'cell' because I couldn't directly set a range to some text without it showing up as '--', even when the column format was 'text'. So this didn't work...
range aa = !1[1];
aa = "test";



jdf726
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 05/09/2017 :  8:16:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Use the ? operator, see

http://www.originlab.com/doc/LabTalk/guide/Operators#Conditional_Operator_.28.3F:.29


For example, I fill column A with row numbers and put the following formula into col B


A>=1&&A<=7?"Low":(A>7&&A<=17?"mid":"high")



CP

Go to Top of Page

jdf726

78 Posts

Posted - 05/10/2017 :  04:53:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I should have prefixed my comment with 'I am a novice, but this is how I would do it' ;-)

cpyang's solution is elegant because it can be pasted into the formula box.

That said, I seem to often end up having to use labtalk scripts, so practising loops and range notation is a good thing for me! (and you can't add 'comments' to your 'conditional logic' string like you can in a script).


jdf726
Go to Top of Page

jdf726

78 Posts

Posted - 05/10/2017 :  05:58:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you explain why writing text data directly into a range doesn't work?

I don't often write text to cells, but I think I have ended up using 'cell' which is described as being 'older' in the documentation.
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 05/10/2017 :  12:23:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi jdf726,

> Can you explain why writing text data directly into a range doesn't work?
> I don't often write text to cells, but I think I have ended up using 'cell' which is described as being 'older'
> in the documentation.

Range is simply a range of cell block or a column - it doesn't care whether it contains the numbers of strings there.
Type mismatching occurs in assignment when destination is received. If you want to receive the Text data in destination,
you can explicitly mark with "$" sign in the assignment.

//When the destination column is "Text" or "Text & Numeric" type:
range rB=col(B);
rB[1]$="High"; (or col(B)[1]$="High";)
  ==> OK. Original string "High" is set to the cell
rB[1]="High"; (or col(B)[1]="High";)
   ==> Error by mismatched data types. The cell gets "--".

//When the destination column is "Text" type: 
col(B)[1]$="009"; (or col(B)[1]$=009;)
  ==> OK. Original string "009" is set to the cell
col(B)[1]=009;
  ==> OK, but converted string "9" is set to the cell
col(B)[1]="009";
  ==> Error by mismatched data types. The cell gets "--".

//When the destination column is "Numeric" type: 
col(B)[1]="0999";
  ==>Error of mismatched data type
col(B)[1]=999;
  ==>OK. It gets 999.
col(B)[1]$="ABC";
  ==>Error of mismatched data type. The cell gets "--".
col(B)[1]$="00999";
  ==> OK. At end, the cell gets 999.

Note: In the Set Column Values tool, the left-side of the equation (just above the box 
for right-side) doesn't show $ like "Col(B)=", but in this case, for your convenience, 
string assignment works.

I hope this explanation is understandable.

--Hideo Fujii
OriginLab
Go to Top of Page

spstills23

1 Posts

Posted - 05/10/2017 :  3:34:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the help! Worked like a charm!
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