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
 Average over datasets ?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jeanbap

alnarp, Sweden
20 Posts

Posted - 07/18/2000 :  12:41:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi !
I have several worksheets RH1 RH2 RH3 of the same length, with a VAL column I want to make an average of.
I want to obtain one new dataset AVG which values are given by the average of RHi's.

AVG(i)=Ave(RH1_VAL[i],RH2_VAL[i],RH3_VAL[i])

Is there a fast way to do that with Origin 5.0 ?

Thanks
JB

Jose

Netherlands
93 Posts

Posted - 07/19/2000 :  1:53:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply

Try the following script (I suppose you have created a fourth worksheet named "rhavg" where you have the results)

rhavg_avg=rh1_val;
rhavg_avg+=rh2_val;
rhavg_avg+=rh3_val; // these three first lines make the sum
rhavg_avg/=3; // this last one divides by 3, so makes the average

You could do this for more worksheets by using loops:

numwks=3; // number of worksheets you want to average (they are all named RH#)

rhavg_avg=rh1_val;

loop (nn,2,numwks) {rhavg_avg+=rh$(nn)_val;}

rhavg_avg/=numwks;

I hope this helps.

jose.

Go to Top of Page

rtoomey

USA
184 Posts

Posted - 07/19/2000 :  2:26:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here's another option:

Create a worksheet called AveRh (not RhAve) and add (or rename) two columns in it so that one is called Averages and the other is called Final. Then, execute the following script:


count=0;
doc -cws rh;
loop(ii,1,count)
{
sum(rh$(ii)_val);
AveRh_Averages[ii]=sum.mean;
};
sum(AveRh_Averages);
AveRh_Final[1]=sum.mean;

To explain:

The first line initializes a variable called count to 0. The second line in this script then determines the number of worksheets in your project which begin with the letters rh and places that number into count. Lines 3 through 7 in the script then loop from 1 to the value in count, perform the sum function on each successive column called rh#_val (where # is a number), and then place that result into a new column (called Averages) in the worksheet called AveRh. Note: The averages worksheet can not be called RhAve in this case since it would be included in the count variable. The last two lines of script then take the average of the averages and report the final average to another column in AveRh (called Final).

[This message has been edited by rtoomey (edited 07-19-2000).]

[This message has been edited by rtoomey (edited 07-19-2000).]

Go to Top of Page

Jose

Netherlands
93 Posts

Posted - 07/19/2000 :  2:42:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear rtoomey,

where you wrote "averh_b" in your script, you should have written "averh_averages", if I correctly understood it. In any case, your script gives, once corrected, the average for every dataset in the first column of "Averh", and then the average of all datasets, as one single number in the second column. My and Jean Baptiste's scripts calculate the average through all datasets *row by row*, that is a different purpose. In any case, by combining yours and mine, I think he would be able to construct the propper one

jose.

Go to Top of Page

rtoomey

USA
184 Posts

Posted - 07/19/2000 :  3:39:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for catching that Jose! I have updated my post.

Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 07/19/2000 :  4:04:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If I didn't misunderstand, to put the following formula in the "Set Column Values" is enough for this purpos.

1. Select the destination column, and choose "Column: Set Column Value".
2. Type (RH1_VAL[i]+RH2_VAL[i]+RH3_VAL[i])/3
and set "For row: to" properly, then click okay.

Is something wrong here?

[This message has been edited by Hideo Fujii (edited 07-19-2000).]

Go to Top of Page

Jose

Netherlands
93 Posts

Posted - 07/19/2000 :  4:15:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hideo,

that's right, your method also gives the desired result, but it is more hard to update when you have more datasets to average. Imagine if you had twenty! In this case, even my first proposal is quite large... "Scripting" with loops makes the work easier, and more general.

j.

Go to Top of Page

jeanbap

alnarp, Sweden
20 Posts

Posted - 07/20/2000 :  8:17:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you guys for your help !

You provided me with lots of solutions. I will try to implement you different proposition and come back with some timings, beause speed is relatively important for me:
I have indeed plenty averages to calculate: RH, O2, CO2, T, for twice 6 columns and 3 values.

Thanks again !

JB

Go to Top of Page

jeanbap

alnarp, Sweden
20 Posts

Posted - 07/21/2000 :  8:09:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hej igen !

I tried Jose's method. It worked well and so fast !!! I was impressed.

The method by rootmey may be faster but it does not give me what I want.

Thanks to all of you.

BTW, is it possible to use Labtalk to extract worksheet data in a fast way?

J-B

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