Hi Kawon,
Please try the following codes, hope help you. I tried in 7.5Sr7, it works.
void average_columns(int nNumColsOfOneGroup = 16)
{
// get source data worksheet containing one X-column and 512 Y-columns
Worksheet wks = Project.ActiveLayer();
if(!wks || 513 != wks.GetNumCols())
{
out_str("No active worksheet or no specified worksheet including one X column and 512 Y columns!");
return;
}
//prepare output worksheet
Worksheet wksOut;
wksOut.Create("origin");
// Copy X data from source worksheet to reuslt worksheet
Dataset dsX(wks, 0);
Dataset dsXNew(wksOut, 0);
dsXNew = dsX;
// average Y columns for each 16 columns and put result to new worksheet
int nBeginCol = 1;
int nEndCol = nBeginCol + nNumColsOfOneGroup - 1;
int nResultCol = 1; //the first column is X, so the first Y column beginning from 1
for(int nNumGroups = 0; ;nNumGroups++)
{
// get data and do average
Column colBegin(wks, nBeginCol);
if(!colBegin)
break;
vector& vData1 = colBegin.GetDataObject();
for(int nCol = nBeginCol+1; nCol <= nEndCol; nCol++)
{
Column col(wks, nCol);
if(!col)
break;
vector& vData2 = col.GetDataObject();
vData1 = vData1 + vData2;
}
vData1 = vData1 / nNumColsOfOneGroup;
// put reuslt into wksOut sheet
Column colResult(wksOut, nResultCol);
if(!colResult)
colResult.Attach(wksOut, wksOut.AddCol());
Dataset dsResult(colResult);
dsResult = vData1;
nResultCol++;
// continue to average next group
nBeginCol += nNumColsOfOneGroup;
nEndCol += nNumColsOfOneGroup;
}
}
Iris