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
 Origin Forum
 Does origin have a "IF function"

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
spstills23 Posted - 05/09/2017 : 3:59:34 PM
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!
6   L A T E S T    R E P L I E S    (Newest First)
spstills23 Posted - 05/10/2017 : 3:34:55 PM
Thanks for the help! Worked like a charm!
Hideo Fujii Posted - 05/10/2017 : 12:23:36 PM
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
jdf726 Posted - 05/10/2017 : 05:58:42 AM
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.
jdf726 Posted - 05/10/2017 : 04:53:35 AM
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
cpyang Posted - 05/09/2017 : 8:16:48 PM
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

jdf726 Posted - 05/09/2017 : 6:38:19 PM
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

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