Hi eno,
And here is an Origin C solution for the same thing:
Cut and paste the code posted below to a new Origin C file.
Once you compile this file, you can then go to script window and enter a command such as
tscompute data1_b 10
which would then create a new worksheet, and compute min, max, mean, and std dev on groups of 10, for the data in data1_b
Easwar
OriginLab.
void tscompute(string strDatasetName, int iGroupSize)
{
// Declare dataset and verify
Dataset dsData(strDatasetName);
if(!dsData)
{
printf("Dataset is not valid!\n");
return;
}
// Check group size
int iSize = dsData.GetSize();
if ( iGroupSize < 0 || iGroupSize > (iSize/2) )
{
printf("Incorrect group size!\n");
return;
}
// Create new wks for results
Worksheet wks;
wks.Create("origin.otw");
// Delete all existing columns
while (wks.Columns(0))
wks.DeleteCol(0);
// Add new colums and assign them label names and set them wide enough
int iColIndex;
iColIndex = wks.AddCol();
wks.Columns(iColIndex).SetLabel("Group No.");
wks.Columns(iColIndex).SetType(OKDATAOBJ_DESIGNATION_X);
wks.Columns(iColIndex).SetWidth(11);
iColIndex = wks.AddCol();
wks.Columns(iColIndex).SetLabel("Group Min");
wks.Columns(iColIndex).SetWidth(11);
iColIndex = wks.AddCol();
wks.Columns(iColIndex).SetLabel("Group Max");
wks.Columns(iColIndex).SetWidth(11);
iColIndex = wks.AddCol();
wks.Columns(iColIndex).SetLabel("Group Mean");
wks.Columns(iColIndex).SetWidth(11);
iColIndex = wks.AddCol();
wks.Columns(iColIndex).SetLabel("Group Std Dev");
wks.Columns(iColIndex).SetWidth(11);
// Turn on label display for columns
wks.ShowLabels();
// Loop over dataset, set the range for each group, and compute stats
BasicStats stat;
int iSteps = iSize / iGroupSize;
for(int ii = 0; ii < iSteps; ii++)
{
int iBegin = ii * iGroupSize;
int iEnd = iBegin + iGroupSize - 1;
dsData.SetLowerBound(iBegin); // set begin marker for dataset
dsData.SetUpperBound(iEnd); // set end marker for dataset
Data_sum(&dsData, &stat); // compute stats
wks.SetCell(ii, 0, ii); // plug values into wks
wks.SetCell(ii, 1, stat.min);
wks.SetCell(ii, 2, stat.max);
wks.SetCell(ii, 3, stat.mean);
wks.SetCell(ii, 4, stat.sd);
}
dsData.SetLowerBound(0); // reset range to full
dsData.SetUpperBound(iSize - 1);
}
Edited by - easwar on 06/25/2003 12:10:44 PM