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
 Set Value
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

nbo10

USA
Posts

Posted - 11/26/2008 :  6:00:53 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.8 and SR (Select Help-->About Origin):
Operating System:xp

I have a column that I use as a flag, it's either p or s. I want to set the value of another column depending on the value of the flag column. How do I do this, I've tried the following code in the "Before formula scripts" but it doesn't run properly.
[code]
if( Col(A)[i] == p)
{
a=Col(CenterX);
b=Col(CenterY);
Col(SpotAngleSan) =atan(a/b);
}

if( Col(A)[i] == s)
{
a=Col(CenterY);
b=Col(CenterX);
Col(SpotAngleSan) =atan(a/b);
}
[\code]

VincentLiu

China
Posts

Posted - 11/27/2008 :  04:39:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You may copy and paste following codes to "Before formula scripts" to set values. Please note that if p and r are characters, please add "" in the scripts. Here we assume p and r are characters.


int i;
for (i=1;i<=wks.maxrows;i++)
{
 if( Col(A)[$(i)] == "p")
 {
   a=Col(CenterX)[$(i)]; 
   b=Col(CenterY)[$(i)];
   Col(SpotAngleSan)[$(i)] =atan(a/b);
 }
 else
 {
   a= Col(CenterY)[$(i)];
   b= Col(CenterX)[$(i)];
   Col(SpotAngleSan)[$(i)] =atan(a/b);
 }
}


For the flag column has only two values p or s, there is another way to solve the problem. You can past the following code in the Column formula (which is in the middle panel of Set Values dialog.):

(col(A)=="p") ? atan(col(CenterX)/col(CenterY)) : atan(col(CenterY)/col(CenterX))

For the computation speed may be slower when you use loop in "Before formula scripts", we recommend you to use the second way to Set Values.

Best regards,
Vincent Liu
OriginLab Technical Services

Go to Top of Page

nbo10

USA
Posts

Posted - 11/27/2008 :  10:37:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
What format does the flag column need to be in?

Thanks for the help but the formula dont evaluate to the expected values. It always always evaluates last formula. When I use the line
(col(A)=="p") ? atan(col(CenterX)/col(CenterY)) : atan(col(CenterY)/col(CenterX))
It always evaluates
atan(col(CenterY)/col(CenterX))
I've tried all combination's of label, disregard, x on the flag column with no change
Go to Top of Page

nbo10

USA
Posts

Posted - 11/27/2008 :  10:39:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I just changed to using either a 0 or 1 for p or s, and everything works out.
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