【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.1.24.4.3 ocmath_2d_binning
Contents
Description
Compute frequency count for 2D binning on two arrays pX and pY.
Syntax
int ocmath_2d_binning( int nSize, const double * pX, const double * pY, BinningResult * pResult, BinningOption * pOptionX = NULL, BinningOption * pOptionY = NULL )
Parameters
- nSize
- [input]size of the X and Y array
- pX
- [input]pointer to buffer of the X array data
- pY
- [input]pointer to buffer of the Y array data
- pResult
- [output]pointer to result structure
- pOptionX
- [input]pointer to the structure of BinningOption for X array. If it is NULL(default), the optional parameters are given by the function.
- pOptionY
- [input]pointer to the structure of BinningOption for Y array. If it is NULL(default), the optional parameters are given by the function.
typedef struct { double dMin; // the minimum of the range double dMax; // the maximum of the range double dInc; // the bin increment of the range int wIncludeOutliers; // flag indicating whether or not to include outliers in first and last bins, values are defined in enum FrequncyAccounOutBin, default value is FAB_NOT_INCLUDE_OUTLIERS double dPeriod; //period for the data int wIncludeMinMax; // reuse flag in wIncludeOutliers, left for Min, right for Max int nMode; // BIN_MODE_INC, BIN_MODE_VALS double* pdVals; // Double Array for BIN_MODE_VALS, for example, fill with 3 7 12 20, min=0, max=30, then the bins should be 0-3, 3-7, 7-12, 12-20, 20-30, >=30 int nValsSize;// The size of pdVals }BinningOption;
Return
Returns 0 on success. Otherwise returns error code:
BINNING_ERR_SIZE: nSize less than 1
BINNING_ERR_RANGE: range is invalid(dMin > dMax)
BINNING_ERR_INC: dInc <= 0 or dInc > dMax - dMin
BINNING_ERR_FLAG: wIncludeOutliers is not defined in the enum
BINNING_ERR_BUFFER_TOO_SMALL: size of pResult->pMatrix is less than needed
Examples
EX1
//This function will output the 2D Binning result into a new Matrix. void ocmath_2d_binning_ex1() { //Worksheet wks = Project.ActiveLayer(); //assume current worksheet is active Worksheet wks; wks.Create("origin.otw"); while(wks.Columns()) wks.DeleteCol(0); for(int n=0; n < 2; n++) wks.AddCol(); DataRange dr; dr.Add("X", wks, 0, 0, -1, 0); dr.Add("Y", wks, 0, 1, -1, 1); vector vX,vY; vX.Data(1,30,1); vY.Normal(30); dr.SetData(&vY, &vX); int nSize = vY.GetSize(); MatrixLayer mResultLayer; mResultLayer.Create(); mResultLayer.SetInternalData(FSI_ULONG); Matrix<uint> matResult(mResultLayer); BinningOption OptionX, OptionY; vX.GetMinMax(OptionX.dMin, OptionX.dMax); RoundLimits(&OptionX.dMin, &OptionX.dMax, &OptionX.dInc); OptionX.wIncludeOutliers = FAB_NOT_INCLUDE_OUTLIERS; int iSizeX = ceil( (OptionX.dMax - OptionX.dMin) / OptionX.dInc ) ; vY.GetMinMax(OptionY.dMin, OptionY.dMax); RoundLimits(&OptionY.dMin, &OptionY.dMax, &OptionY.dInc); OptionY.wIncludeOutliers = FAB_NOT_INCLUDE_OUTLIERS; int iSizeY = ceil( (OptionY.dMax - OptionY.dMin) / OptionY.dInc ) ; BinningResult Result; matrix<uint> mResult(iSizeX, iSizeY); Result.iMatSize = iSizeX * iSizeY; Result.pMatrix = mResult; int iRet = ocmath_2d_binning(nSize, vX, vY, &Result, &OptionX, &OptionY); if(iRet) { printf("Error code is %d", iRet); return; } matResult = mResult; }
Remark
See Also
Header to Include
origin.h