2.1.17.2.7.4 ocmath_reducexy_n_groups


Description

Reduce XY data by number of groups

Syntax

Origin 2021 and later versions
int ocmath_reducexy_n_groups(const double * px, const double * pData, const UINT nSize, const int iOption, double * pMerged, int nBins, 
                             const double dStart = 0.0, const double dEnd = 0.0, UINT *pnMergedIndex = NULL, DWORD dwCntrl = 0)
Origin 2019 and later versions
int ocmath_reducexy_n_groups(const double * px, const double * pData, const UINT nSize, const int iOption, double * pMerged, int nBins, 
                             const double dStart = 0.0, const double dEnd = 0.0, UINT *pnMergedIndex = NULL)
Origin 2017 and later versions
int ocmath_reducexy_n_groups(const double * px, const double * pData, const UINT nSize, const int iOption, double * pMerged, int nBins, 
                             const double dStart = 0.0, const double dEnd = 0.0 )
Origin 2016
int ocmath_reducexy_n_groups(const double * px, const double * pData, const UINT nSize, const double nStart, const double nEnd, 
                             const int iOption, double * pMerged, int nBins);
Origin 2015 and older versions
int ocmath_reducexy_n_groups(const double * px, const double * pData, const UINT nSize, const int iOption, double * pMerged, int nBins);

Parameters

px
[input] pointer to x coordinates of the data
pData
[input] pointer to y coordinates of the data
nSize
[input] the number of the data points
iOption
[input] the way to pick the data value of the output data point, into which a group of data points are merged.
pMerged
[output] pointer to buffer to store the reduced data
nBins
[input] the number of the bins
dStart
[input] the start of x coordinates of the data(for subgroup using)
dEnd
[input] the end of x coordinates of the data(for subgroup using)
pnMergedIndex
[output] pointer to buffer to store the index of reduced data in source data
dwCntrl
[input] additional control, can be
REDUCE_XY_CNTRL_EXCLUDE_MISSING_VALUE

Return

Return the number of points in pMerged, return minus value on failure.

Examples

EX1

//Before run this sample code, please import "\\Samples\Mathematics\Circle.dat" into active worksheet, and set the number of rows as 27.


//Funtion prototype has been modified in Origin 2017 SR0. 
//If you want to execute the following function in Origin 2016 and older versions, 
//please replace ocmath_reducexy_n_groups with its corresponding prototype.
void ocmath_reducexy_n_groups_ex1()
{
    Worksheet wks = Project.ActiveLayer();
    if ( !wks )
        return;
    Column colX(wks, 0);
    Column colY(wks, 1);
    if ( colX && colY )
    {
        vectorbase& vbInterX = colX.GetDataObject();
        vectorbase& vbInterY = colY.GetDataObject();
        vector vX = vbInterX; //should not pass vectorbase& as double pointer, need to temp it
        vector vY = vbInterY;
        
        vector vReduced(vY.GetSize());
        int nOption = REDUCE_XY_STATS_MEAN; //can change to other option in REDUCE_XY_STATS_...
        int nBins = 8;
        int nNewSize = ocmath_reducexy_n_groups(vX, vY, vY.GetSize(), nOption, vReduced, nBins);
        
        int iReduced = wks.AddCol("Reduced");
        Column colReduced(wks, iReduced);
        vectorbase& vbReduced = colReduced.GetDataObject();
        vbReduced = vReduced; //put result in new column;
    }
    return;
}

//Funtion prototype has been modified in Origin 2017 SR0. 
//If you want to execute the following function in Origin 2016 and older versions, 
//please replace ocmath_reducexy_n_groups with its corresponding prototype.
void ocmath_reducexy_n_groups_ex2()
{
    Worksheet wks = Project.ActiveLayer();
    if ( !wks )
        return;
    Column colX(wks, 0);
    Column colY(wks, 1);
    if ( colX && colY )
    {
        vectorbase& vbInterX = colX.GetDataObject();
        vectorbase& vbInterY = colY.GetDataObject();
        vector vX = vbInterX; //should not pass vectorbase& as double pointer, need to temp it
        vector vY = vbInterY;
 
        vector vReduced(vY.GetSize());
        int nOption = REDUCE_XY_STATS_SUBGROUP_BEGIN; //can change to other option REDUCE_XY_STATS_SUBGROUP_CENTER and REDUCE_XY_STATS_SUBGROUP_END
        int nBins = 8;
        double dStart = 0.2;
        double dEnd = 0.8;
        int nNewSize = ocmath_reducexy_n_groups(vX, vY, vY.GetSize(), nOption, vReduced, nBins, dStart, dEnd);
 
        int iReduced = wks.AddCol("Reduced");
        Column colReduced(wks, iReduced);
        vectorbase& vbReduced = colReduced.GetDataObject();
        vbReduced = vReduced; //put result in new column;
    }
    return;
}
//Funtion prototype has been modified in Origin 2019 
//If you want to execute the following function in Origin 2019 and older versions, 
//please replace ocmath_reducexy_n_groups with its corresponding prototype.
void ocmath_reducexy_n_groups_ex3()
{
    Worksheet wks = Project.ActiveLayer();
    if ( !wks )
        return;
    Column colX(wks, 0);
    Column colY(wks, 1);
    if ( colX && colY )
    {
        vectorbase& vbInterX = colX.GetDataObject();
        vectorbase& vbInterY = colY.GetDataObject();
        vector vX = vbInterX; //should not pass vectorbase& as double pointer, need to temp it
        vector vY = vbInterY;
 
        vector vReduced(vY.GetSize());
        vector<UINT> vnReducedIndex(vY.GetSize());
        int nOption = REDUCE_XY_STATS_SUBGROUP_BEGIN; //can change to other option REDUCE_XY_STATS_SUBGROUP_CENTER and REDUCE_XY_STATS_SUBGROUP_END
        int nBins = 8;
        double dStart = 0.2;
        double dEnd = 0.8;
        int nNewSize = ocmath_reducexy_n_groups(vX, vY, vY.GetSize(), nOption, vReduced, nBins, dStart, dEnd, vnReducedIndex);
 
        int iReduced = wks.AddCol("Reduced");
        Column colReduced(wks, iReduced);
        vectorbase& vbReduced = colReduced.GetDataObject();
        vbReduced = vReduced; //put result in new column;
    }
    return;
}

Remark

Function prototype was modified at Origin 2019

See Also

Header to Included

origin.h

Reference