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
 Formula with "if" loop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

dominik.mierzwa

Poland
118 Posts

Posted - 02/16/2021 :  11:59:36 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,
I measured three parameters for two materials (C and D). I organized it in the indexed sheet and would like to calculate the formula:
dE=sqrt((a2-a1)^2+(b2-b1)^2+(c2-c1)^2)
where
a2, b2, and c2 are mean for raw material C (raw_C) or D (raw_D), and a1, b1, and c1 are measurements for treated material (VI50_C, VI300_C, VI50_D and VI300_D).
I would like to calculate dE for each row (except raw_C and raw_D). What is important the dE should be calculated with a proper mean value of a2, b2, and c2. I think that I need to use the “If…else” loop but I cannot solve this. Is there any way to do this with labtalk?

https://my.originlab.com/ftp/forum_and_kbase/Images/example%20data.opju

Kind regards,
Dominik

Edited by - dominik.mierzwa on 02/16/2021 12:00:34 PM

snowli

USA
1391 Posts

Posted - 02/16/2021 :  12:25:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

We have averageif() function to calculate averages with some condition met.
https://www.originlab.com/doc/LabTalk/ref/Averageif-func

E.g. averageif(B, "col(A)$="raw_C"") will calculate a2 for you.

Your question isn't clear. " a1, b1, and c1 are measurements for treated material (VI50_C, VI300_C, VI50_D and VI300_D)".

But i think averageif() is what you are looking for to calculate a1, a2, b1, b2, .... and then u can calculate dE

Thanks, Snow
Go to Top of Page

dominik.mierzwa

Poland
118 Posts

Posted - 02/16/2021 :  12:50:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by snowli

Hello,

Your question isn't clear. " a1, b1, and c1 are measurements for treated material (VI50_C, VI300_C, VI50_D and VI300_D)".

Thanks, Snow




Hi,

thank you for the fast reply. Well, averageif solve problem partially. Firstly, to calculate dE I need average value of a, b and c for raw_C and raw_D. Next for each row different from raw_C and raw_D I would like to calculate dE in accordance with the previously defined formula.

Now, for each row:
If in col(A) name "VI50_C" or "VI300_C" is present then Origin should use the average of raw_C as (a2, b2 and c2)
If in col(A) name "VI50_D" or "VI300_D" is present then Origin should use the average of raw_D as (a2, b2 and c2)
If in col(A) is "raw_C or "raw_D" Origin should leave it or fill with ""

Kind regards,
Dominik

Edited by - dominik.mierzwa on 02/16/2021 12:50:51 PM
Go to Top of Page

snowli

USA
1391 Posts

Posted - 02/16/2021 :  2:21:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We also have if(condition, true_expression, false expression )
originlab.com/doc/LabTalk/ref/If-func

E.g. try to put the following in dE's formula and before formula script boxes respectively and see if it's what you want

if(A$=="V*C", sqrt((a2c-B)^2+(b2c-C)^2+(c2c-D)^2),
if(A$=="V*D", sqrt((a2d-B)^2+(b2d-C)^2+(c2d-D)^2),
--))

double a2c=averageif(col(B), "col(A)$=="raw_C"");
double b2c=averageif(col(C), "col(A)$=="raw_C"");
double c2c=averageif(col(D), "col(A)$=="raw_C"");
double a2d=averageif(col(B), "col(A)$=="raw_D"");
double b2d=averageif(col(C), "col(A)$=="raw_D"");
double c2d=averageif(col(D), "col(A)$=="raw_D"");


Thanks, Snow
Go to Top of Page

dominik.mierzwa

Poland
118 Posts

Posted - 02/17/2021 :  09:53:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Works perfectly! Thank you! The point I stopped at was "A$=="V*C" Now, I know how to do this.

Kind regards,
Dominik
Go to Top of Page

snowli

USA
1391 Posts

Posted - 02/17/2021 :  11:08:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry that I didn't explain that.
Yes. We support wildcard in condition which makes the condition easier.
Also you can define variables in Before Formula Script and use them in formula. This way the formula is easier.

Great to know it works.

Thanks, Snow
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