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 for Programming
 Forum for Origin C
 Calculate mean and substract from column

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
Kaemme1909 Posted - 06/06/2013 : 04:59:02 AM
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.
3   L A T E S T    R E P L I E S    (Newest First)
Kaemme1909 Posted - 06/06/2013 : 05:32:06 AM
Works fine. Thank you very much.
Penn Posted - 06/06/2013 : 05:19:39 AM
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
Kaemme1909 Posted - 06/06/2013 : 05:04:48 AM
I think the problem must be in this part col4.SetFormula("col4-bsStat.mean");

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