ocmath_reducexy_n_points

 

Description

Reduce XY data by every N points

Syntax

Syntax

Origin 2021 and later versions
int ocmath_reducexy_n_points(const double *pData, double *pDataMerged, const UINT nSize, const UINT nPoints, int iOption, 
                             UINT *pDataMergedIndex = NULL, DWORD dwCntrl = 0)
Origin 2019 and later versions
int ocmath_reducexy_n_points(const double *pData, double *pDataMerged, const UINT nSize, const UINT nPoints, int iOption, UINT *pDataMergedIndex = NULL)
Origin 2019 and older versions
int ocmath_reducexy_n_points( const double * pData, double * pDataMerged, const UINT nSize, const UINT nPoints, int iOption )

Parameters

pData
[input] pointer to y coordinates of the data
pDataMerged
[output] pointer to buffer to store the reduced data
nSize
[input] the number of the data points
nPoints
[input] the number of points in each group
iOption
[input] the way to pick the data value of the output data point, into which a group of data points are merged.
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.

void ocmath_reducexy_n_points_ex1()
{
        Worksheet wks = Project.ActiveLayer();
        if ( !wks )
                return;
        Column colX(wks, 0);
        Column colY(wks, 1);
        if ( colX && colY )
        {
                vectorbase& vbInterY = colY.GetDataObject();
                vector vY = vbInterY;
 
                vector vReduced(vY.GetSize());
                int nOption = REDUCE_XY_STATS_MEAN; //can change to other option in REDUCE_XY_STATS_...
                int nPoints = 3; //number of points in each group
                int nNewSize = ocmath_reducexy_n_points(vY, vReduced, vY.GetSize(), nPoints, nOption);
 
                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 2018 and older versions, 
//please replace ocmath_reducexy_fixing_increbin with its corresponding prototype.
void ocmath_reducexy_n_points_ex2()
{
        Worksheet wks = Project.ActiveLayer();
        if ( !wks )
                return;
        Column colX(wks, 0);
        Column colY(wks, 1);
        if ( colX && colY )
        {
                vectorbase& vbInterY = colY.GetDataObject();
                vector vY = vbInterY;
 
                vector vReduced(vY.GetSize());
                vector<UINT> vnReducedIndex(vY.GetSize());
                int nOption = REDUCE_XY_STATS_MEAN; //can change to other option in REDUCE_XY_STATS_...
                int nPoints = 3; //number of points in each group
                int nNewSize = ocmath_reducexy_n_points(vY, vReduced, vY.GetSize(), nPoints, nOption, vnReducedIndex);
 
                int iReduced = wks.AddCol("Reduced");
                Column colReduced(wks, iReduced);
                vectorbase& vbReduced = colReduced.GetDataObject();
                vbReduced = vReduced; //put result in new column;
        }
        return;
}

Remark

See Also

Header to Included

origin.h

Reference