ocmath_linear_transform

 

Description

Map data array slope [min, max] to [nMin, nMax] linearly

Syntax

int ocmath_linear_transform( double * pData, uint i1, uint i2, int nMin, int nMax, double dMin = __NANUM, double dMax = __NANUM, DWORD dwCntrl = 0 )

Parameters

pData
[modify] pointer to data array
i1
[input] start data index
i2
[input] end data index (inclusive)
nMin
[input] result min
nMax
[input] result max
dMin
[input] input data min to be mapped to nMin, use NANUM to get actual data min
dMax
[input] input data max to be mapped to nMax, use NANUM to get actual data max
dwCntrl
[input] bits of LNTR_NO_ROUND_NEAREST_INT etc

Return

0 if success, -1 if dMin and dMax equal

Examples

EX1

void ocmath_linear_transform_ex1()
{
     vector vx2 = {100,200,300,400,500};
     vector vx;
     vx = vx2;
     int nErr = ocmath_linear_transform(vx, 0, vx.GetSize(), 0, 255, NANUM, NANUM);
     for(int ii = 0; ii < vx.GetSize(); ii++)
     {
         int nn = vx[ii];
         printf("%d ", nn);
     }
     out_str("");
     //output should be "0 64 127 191 255" 
}

Remark

See Also

header to Include

origin.h

Reference