Author |
Topic |
|
cyndi.y.ri
USA
11 Posts |
Posted - 02/05/2016 : 11:57:28 AM
|
I am trying to write a script for If Else I have searched and searched trying to figure it out and have not had success.
It is basically if the new is greater than the initial do one equation and if it is lesser than the initial do a different equation.
Here is the script I have been playing with
for(i=1;i<100;i+1){col(Delta)[i]=(col(InitialTemp)[i]-col(NewTemp)[i])};
for(i=1;i<100;i+1){col(Absolute)[i]=(abs(col(Delta)[i]))};
for(i=1;i<100;i+1){col(Change)[i]=(col(Steel)[i]*col(Absolute)[i]*col(InitialMeasure)[i])/100};
for(i=1;i<100;i+1){col(Outcome)[i]=
col(InitialTemp)[i]<col(NewTemp)[i])} :
{(col(InitialMeasure)[i])-col(Change)[i])-col(NewMeasure)[i]};
for(i=1;i<100;i+1){col(Outcome)[i]=if((col(InitialTemp)[i]>col(NewTemp)[i]))};
{(col(InitialMeasure)[i])+col(Change)[i])-col(NewMeasure)[i]};
|
|
snowli
USA
1381 Posts |
Posted - 02/05/2016 : 2:24:58 PM
|
Origin supports conditional operator. http://www.originlab.com/doc/LabTalk/guide/Operators#Conditional_Operator_.28.3F:.29
Expression1 ? Expression2 : Expression3
e.g. col(C)=col(A)>col(B)? col(E)+col(F): col(E)-col(F) //if value in A bigger than B, fill col(C) with sum of vlaues in E and F, otherwise fill col(C) with subtraction of E and F.
I am wondering why you don't use Set Column Values dialog which can help you setup the formula in each column and save it as a template for future calcualtion. http://originlab.com/Index.aspx?go=Support/VideoTutorials&pid=1556
If you must use the Script, to loop through all rows in worksheet, you don't need to use for loop, unless you only want loop 100 rows. you can directly write col(Delta)=col(Initialtemp)-col(NewTemp); col(Absolute)=abs(col(Delta)); and so on.
Thanks, Snow
|
|
|
cyndi.y.ri
USA
11 Posts |
Posted - 02/05/2016 : 2:41:30 PM
|
Thank YOU!!!
But it doesn't seem to work for the negative equation. Have I gotten something incorrect?
col(Outcome)=col(InitialTemp)>col(NewTemp)? col(InitialMeasure)+col(Change): col(InitialMeasure)-col(Change);
I use the old script style because that is the way I started yrs ago. I haven't had time to learn all the updates. I am swamped all the time. One day I would love to learn all the new stuff to make my job easier. Right now this is the best I can do. |
Edited by - cyndi.y.ri on 02/05/2016 2:47:13 PM |
|
|
snowli
USA
1381 Posts |
Posted - 02/05/2016 : 3:44:57 PM
|
Could you let me know which version of Origin are you using?
I tried the code you pasted. As long as i have those columns, i can run it fine.
Could you send your opj to tech@originlab.com so that we could take a look?
Thanks, Snow |
|
|
cyndi.y.ri
USA
11 Posts |
Posted - 02/08/2016 : 08:02:55 AM
|
I am using OriginPro 9.1.0
Waiting on our update to 2016
for(i=1;i<100;i+1){col(Delta)[i]=(col(InitialTemp)[i]-col(NewTemp)[i])};
for(i=1;i<100;i+1){col(Absolute)[i]=(abs(col(Delta)[i]))};
for(i=1;i<100;i+1){col(Change)[i]=(col(Steel)[i]*col(Absolute)[i]*col(InitialMeasure)[i])/100};
col(Outcome)=col(InitialTemp)>col(NewTemp)? col(InitialMeasure)-col(Change): col(InitialMeasure)+col(Change);
for(i=1;i<100;i+1){col(Inches)[i]=(col(Outcome)[i]-col(NewMeasure)[i])*12};
If I use this
col(Outcome)=col(InitialTemp)>col(NewTemp)?
the outcome is correct The if/else isn't working for "<" |
Edited by - cyndi.y.ri on 02/08/2016 09:26:45 AM |
|
|
snowli
USA
1381 Posts |
Posted - 02/09/2016 : 09:25:29 AM
|
I am not sure what you mean by < not working, do you mean the expression after : isn't working?
From the original image you posted, the InitialTemp values are all bigger than NewTemp, therefore, only the expression before : is used. The expression after : will only be executed if InitialTemp is smaller than NewTemp.
Maybe you should have a screenshot of some rows where initialtemp is smaller than newtemp but calculation is wrong. Or better, send an opj to tech@originlab.com so it's easier for us to take a look.
Thanks, Snow |
|
|
|
Topic |
|