| T O P I C R E V I E W |
| jamaklin |
Posted - 01/08/2007 : 08:47:18 AM Origin Version (Select Help-->About Origin): 7.5 Operating System: Windows XP
Hi! I haven't much experience with origin and I have this kind of problems. I have to calculate mean(average) from a portion of column values: let's say I have 500 values but I need mean from values 100-200. How can I calculate it with Origin C. I have tried Data_sum, but how can I use just a portion of data with it or is it even possible? Do I have to write my own function to do that? Second problem is creating graph automatically from desired columns.
Thank You for advance! |
| 12 L A T E S T R E P L I E S (Newest First) |
| jamaklin |
Posted - 01/19/2007 : 06:32:09 AM Now it has been working fine. There was just a little bug to be fixed... Thanks anyway!
-J- |
| zachary_origin |
Posted - 01/11/2007 : 10:02:58 AM Hi jamaklin,
If you are willing to help us to find the problem and the privacy is permitted, would you mind send both your code and the data file to zachary@originlab.com.cn or tech@originlab.com £¿ It is great appreciated.
Zachary OriginLab Technical Services.
Edited by - zachary_origin on 01/11/2007 10:20:50 AM |
| jamaklin |
Posted - 01/11/2007 : 03:53:01 AM Thanks again. I tried quite similar commands before, but they didn't work. Maybe because of I didn't have gl. at the beginning.
To Zachary: I still have this problem that I need to run my function twice to get it right. My build is same as yours: Origin 7.5 SR6 v7.5885. Should I send one of my codes to you, if you wanted to check it out for errors.
-J- |
| Mike Buess |
Posted - 01/10/2007 : 09:27:53 AM Note: To be safe you should apply LT_execute to the graph layer...
gl.LT_execute("Label -xb x axis text;"); gl.LT_execute("Label -yl y axis text;"); gl.LT_execute("yl.rotate = 90"); // rotate label 90 degrees
Mike Buess Origin WebRing Member |
| jamaklin |
Posted - 01/10/2007 : 09:06:35 AM Thank You both! Very useful information. But I have a minor question left... How can I rotate the axis label? My y-axis label is long, so it needs to be vertically, not horizontally. It's not big issue, but when you have dozens of graph pages, then it comes handy to have it initially vertically. I haven't found anything that could help me. Should these labels be done with some other way or what? Part of my code is below...
LT_execute("Label -xb x axis text;"); LT_execute("Label -yl y axis text;");
-J-
Edited by - jamaklin on 01/10/2007 09:08:46 AM |
| Mike Buess |
Posted - 01/10/2007 : 07:59:57 AM 3> You can also set the scale directly from Origin C. (gl is GraphLayer declared earlier.)
gl.X.From = 0; // set left limit to 0 gl.X.To = 100; // set right limit to 100 gl.GetPage().Refresh(); // refresh to show change
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/10/2007 09:14:59 AM |
| zachary_origin |
Posted - 01/10/2007 : 03:20:03 AM Hi jamaklin,
1 > The reason for the code:
dsColN [0] = bsStat1.mean; dsColN [1] = bsStat2.mean;
does not work is because the size for dsColN is not set. If you add a line
dsColN.SetSize(100); //here 100 is a number not less than the actual elements number for the dataset will store.
before the above lines, it will work.
2 > Why you need run the program twice, I can not reproduce the problem in my build. What is your build? (you can see this by selecting Help: About Origin, and in the dialog there is some info like: OriginPro 7.5 SR6 v7.5885). If it is not SR6, you can try to update it.
3 > To set X-axis start from 0, you can use LT_execute("Layer.x.from = 0;");
4 > By the way, seems you need calculate the mean of several columns, so why not use a for...loop to implement this? The following is a sample code:
void UseLoop() { Worksheet wks = Project.ActiveLayer(); Dataset dsRes(wks,8); //the 9th column, for the column number starts from 0 in OriginC int nCols = 8;// there are 8 columns should be analysised. dsRes.SetSize(nCols); for(int ii = 0; ii< nCols; ii++) { // the first 8 columns should be analysised Dataset dsColCur(wks,ii); BasicStats bsStat; Data_sum(&dsColCur,&bsStat); dsRes[ii]=bsStat.mean; } }
Zachary OriginLab Technical Services. |
| jamaklin |
Posted - 01/10/2007 : 02:23:29 AM Thanks again! Sorry bother you again, but why I have to run the program twice to get it working right?? It builds it ok with no errors or warnings, but when I execute it from the code builder, the resulting cells are blank (or actually they have "-" characters), but when I run it the second time, it works as it should... Why this happens?
And what about the scaling? How can I scale the x-axis so that it starts from 0?
-J- |
| Mike Buess |
Posted - 01/09/2007 : 09:06:10 AM 1) Use one of these methods...
dsColN.Add(bsStat1.mean); dsColN.Add(bsStat2.mean); ...
-or-
wks.SetCell(0,13,bsStat1.mean); wks.SetCell(1,13,bsStat2.mean); ...
2) Use goLegend.X = gl.X.To - goLegend.DX/2.0
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/09/2007 09:27:31 AM |
| jamaklin |
Posted - 01/09/2007 : 02:47:53 AM Thank You very much! It helped me. But... How can I insert the bsStat.mean into specific location. I have many columns (over 10) where I have to calculate it and I got it working like this: Dataset dsColN(wks,13); BasicStats bsStat1; Data_sum(&dsColJ,&bsStat1); dsColN = bsStat1.mean; Dataset dsColO(wks,14); BasicStats bsStat2; Data_sum(&dsColK,&bsStat2); dsColO = bsStat2.mean;
and so on...
As you can imagine, it takes a lot space. I want to insert those bsStatn.mean values into same column, but how? I tried following: dsColN [0] = bsStat1.mean; dsColN [1] = bsStat2.mean; ... but it didn't work...
Second question is about plotting. How can I change the scaling settings? Now my graphs starts from negative x-values and stops before reaching end of x-values... I also want the legend in the right upper corner, not in the middle... Below is part of my graphing code. Thank you for advance.
GraphPage gp; gp.Create(); GraphLayer gl = gp.Layers(0); Curve cv1(wks,0,21); Curve cv2(wks,0,22);
gl.AddPlot(cv1,IDM_PLOT_LINE); gl.AddPlot(cv2,IDM_PLOT_LINE); gl.GroupPlots(0); gl.Rescale(); LT_execute("Legend"); GraphObject goLegend; goLegend = gl.GraphObjects("Legend"); -J-
Edited by - jamaklin on 01/09/2007 06:01:49 AM
Edited by - jamaklin on 01/09/2007 06:05:21 AM |
| zachary_origin |
Posted - 01/08/2007 : 11:02:00 AM As for calculation the mean of a portion of dataset, you can also use the following method other than the method Mike has provided.
// Worksheet column Data1_A must exist prior to execution Dataset dsA("Data1_A"); dsA.SetSize(10); for(int ii = 0; ii < 10; ii++) dsA[ii] = ii;
dsA.SetLowerBound(2); dsA.SetUpperBound(7); BasicStats bsStatVal; Data_sum(&dsA, &bsStatVal); ASSERT( bsStatVal.min == 2 ); ASSERT( bsStatVal.max == 7 );
Zachary OriginLab Technical Services. |
| Mike Buess |
Posted - 01/08/2007 : 10:10:52 AM Just copy the desired rows to a new dataset like this...
Worksheet wks = Project.ActiveLayer(); Dataset ds1(wks,1); // declare col 2 as dataset Dataset ds2(0); // create temporary dataset Data_copy(&ds2,&ds1,99,199,0); // copy rows 100-200 from ds1 to ds2 BasicStats bsStat; Data_sum(&ds2,&bsStat); out_double("mean=",bsStat.mean); // mean of ds2 GraphPage gp; gp.Create(); // create graph page GraphLayer gl = gp.Layers(0); // declare graph layer Curve cv(wks,0,1); // declare col 2 as curve gl.AddPlot(cv,201); // create scatter plot of col 2 gl.Rescale(); // rescale to show all data
Mike Buess Origin WebRing Member |