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 for Programming
 Forum for Origin C
 Calculate mean and substract from column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Kaemme1909

8 Posts

Posted - 06/06/2013 :  04:59:02 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 9.0.0G
Operating System:Win7 (64Bit)
Hi everybody,

I try to calculate the mean of a part of a column and then substract the mean from the whole column. This is my code:

foreach(Column col4 in wks.Columns){
Dataset ds1("col4");
Dataset ds2(0);
Data_copy(&ds2,&ds1,0,830,0);
BasicStats bsStat;
Data_sum(&ds2,&bsStat);
col4.SetFormula("col4-bsStat.mean");
col4.ExecuteFormula();
}

While compilation no error occurs, but when I run the script on my test file the error variable not defined: col4 occurs. Thanks for your help.

Kaemme1909

8 Posts

Posted - 06/06/2013 :  05:04:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I think the problem must be in this part col4.SetFormula("col4-bsStat.mean");
Go to Top of Page

Penn

China
644 Posts

Posted - 06/06/2013 :  05:19:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Two issues to be paid attention to:

1. Dataset ds1("col4");
I am not sure if you want to get the data in col4 (Column variable in your code). If so, please use

Dataset ds1(col4);

2. col4.SetFormula("col4-bsStat.mean");
Please note that this line is trying to set a formula for the calculation of a column, just like right click on the column, and then select "Set Column Values". It runs LabTalk script in the Set Column Values dialog, so if you put "col4-bsStat.mean" to this dialog, it cannot tell what col4 and bsStat.mean mean. You can change it by constructing a LabTalk script, such as

col4.SetFormula("col(" + col4.GetName() + ") - " + bsStat.mean);

After correcting these two lines, it works.


Penn
Go to Top of Page

Kaemme1909

8 Posts

Posted - 06/06/2013 :  05:32:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Works fine. Thank you very much.
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