2.2.4.9.18 DataRange::GetNumDataGetNumData
Description
Get the number of data ranges according to the rules dwRules.
Get the number of subranges.
Syntax
int GetNumData( DWORD dwRules, TreeNode & trAdditionalData = NULL, Worksheet * pwksFirstRange = NULL, vector<int> * pvFactorSizes = NULL, int * pnNumSubRanges = NULL )
int GetNumData( )
Parameters
- dwRules
- [input]the optional bits from the DRR_ enumeration.
- trAdditionalData
- [input]
- pwksFirstRange
- [output] worksheet object of the first data range.
- pvFactorSizes
- [output] the number of items for each factor
- pnNumSubRanges
- [output] the number of sub ranges.
Return
return the number of data ranges according to the rules dwRules.
If dwRules == DRR_RM_ANOVA, it returns one of the values from the enumeration
RMDATA which describes the success or failure of the case of Repeated
Measurements ANOVA data extraction. The number of subranges including separator.
Examples
EX1
//This example need active a graph with selected plot. Will prints out the minimum and
//maximum X and Y values in the selected subranges of the active graph.
void DataRange_GetNumData_Ex1()
{
Tree trXYSelection;
DWORD dwRules = DRR_GET_DEPENDENT | DRR_NO_FACTORS;
init_input_data_branch_from_selection(trXYSelection, dwRules);
// out_tree(trXYSelection);
DataRange dr, drSub;
dr.Create(trXYSelection, false);
DWORD dwPlotID; // This is to retrieve DataPlot UID if present
vector vX, vY;
double xmin, xmax, ymin, ymax;
string strRange;
int nNumRanges = dr.GetNumData(dwRules);
for( int nIndex = 0; nIndex < nNumRanges; nIndex++ )
{
// Copy data associated with nIndex of dr into vectors using DataRange::GetData
dr.GetData(dwRules, nIndex, &dwPlotID, NULL, &vY, &vX);
// Now we have made a copy of XY data into vectors vX and vY
// so we can do analysis on the data...for example:
vX.GetMinMax(xmin, xmax);
vY.GetMinMax(ymin, ymax);
dr.GetSubRange(drSub, dwRules, nIndex);
strRange = drSub.GetDescription();
printf("%s\nxmin = %g\nxmax = %g\nymin = %g\nymax = %g\n", strRange, xmin, xmax, ymin, ymax);
}
}
EX2
// This example assumes 1 or more columns of main data, 1 column of factor or grouping data, and 1 column of weight data
//Print out the maximum, minimum, mean, and factor of the main data in the datarange.
void DataRange_GetNumData_Ex2(int nXColStart = 0, int nXColEnd = 1, int nFCol = 2, int nWCol = 3)
{
Worksheet wks = Project.ActiveLayer();
if( wks )
{
DWORD dwRules = DRR_GET_MISSING | DRR_BAD_WEIGHT_TREATMENT;
DataRange dr;
dr.Add("X", wks, 0, nXColStart, -1, nXColEnd); // Main data
dr.Add("F", wks, 0, nFCol, -1, nFCol); // Factor data
dr.Add("W", wks, 0, nWCol, -1, nWCol); // Weight data
int nNumData = dr.GetNumData(dwRules);
vector<string> vstrFactors;
vector vX, vW;
double dN, dMean, dMax, dMin;
for( int ii = 0; ii < nNumData; ii++ )
{
int nCol = dr.GetData(dwRules, ii, NULL, NULL, &vX, NULL, NULL, &vstrFactors, &vW);
if ( 0 <= nCol )
{
vX *= vW;
dN = vX.GetSize();
vX.Sum(dMean);
dMean /= dN;
vX.GetMinMax(dMin, dMax);
printf("\nColumn = %s, Factor = %s\nMean = %g\nMinimum = %g\nMaximum = %g\n",
wks.Columns(nCol).GetName(), vstrFactors[0], dMean, dMin, dMax);
}
}
}
}
EX3
// This example assumes a worksheet with two columns of data is active.
//Get number of subranges.
void DataRange_GetNumData_Ex3()
{
Worksheet wks = Project.ActiveLayer();
if( !wks )
return;
DataRange dr;
dr.Add(wks, 0, "A");
dr.Add();
dr.Add(wks, 1, "B");
int nNumData = dr.GetNumData(); // should return 3, range A, separator and range B.
}
Remark
See Also
DataRange::GetNumRanges
Header to Include
origin.h
|