Function to compute percentiles (vector) for the vectors passing the percents and data.
int ocmath_percentiles( const double * pData, const int nSize, const double * pPercents, const int nPercentSize, double * pPercentiles, int nInterpolate = INTERPOLATE_WEIGHT_AVER_RIGHT, const double * pWeight = NULL )
Returns STATS_NO_ERROR on successful exit and a non-zero STATS error code on failure.
void ocmath_percentiles_ex1() { //--- Input data and percents for calculate the percentiles int nDataSize = 11; // odd number of data points // vector vData(nDataSize); vector vData={1.0,1.0,2.0,3.0,3.0,3.0,5.0,6.0,7.0,8.0,9.0}; int nPercents = 3; // vector vPercents(nPercents); vector vPercents = {50,70,80}; // 50%, 70% percents etc // The way to calculate the percentiles int nInterpolateType = INTERPOLATE_EDF; //--- Output vector to store the percentiles vector vPercentiles(nPercents); //--- Calculate the percentiles ocmath_percentiles(vData,nDataSize,vPercents,nPercents,vPercentiles,nInterpolateType); //--- Print and show the percentiles printf("\n"); for(int i=0; i<nPercents; i++) { printf("%f ", vPercentiles[i]); } printf("\n"); // For 50% percent, the corresponding returned element in percentiles vector is equal to the median value of the data vector // Expected result: 3.0 6.0 7.0 }
origin.h