2.1.17.2.11 ocmath_ave_replica_data_for_multiple_curves


Description

This function averages replicate data of multiple curves. curve could be monotonic or not monotonic, after average, X data of result should be assending. number of curve could be 1.

Syntax

int ocmath_ave_replica_data_for_multiple_curves( uint nSize, const OneCurveData * pCurves, int * pnAveSize, double * pAveX, double * pAveY, double * pAveErr = NULL, int nErrType = AVMC_SE, int * pAveCount = NULL, double* pAveMin = NULL, double* pAveMax = NULL )

Parameters

nSize
[input] number of curves.
pCurves
[input] pointer to structures that must be filled with pointers to input data.
pnAveSize
[modify] on input, allocated memory size of pAveX, pAveY and pAveErr buffer;
on output, size of pAveX, pAveY and pAveErr buffer, which are determined internally.
pAveX
[output] pointer to buffer to receive X values for the averaged curve.
pAveY
[output] pointer to buffer to receive Y values for the averaged curve.
pAveErr
[output] if not NULL, pointer to buffer to receive the error bar data for the
averaged curve. Its default value is NULL.
nErrType
[input] returns standard error of mean (SEM) or standard deviation in pAveErr
array. Its default value is AVMC_SE.
pAveCount
[output] if not NULL, pointer to buffer to receive count of averaged values for
each point of the averaged curve. Its default value is NULL.
pAveMin
[output] if not NULL, pointer to buffer to receive min data for the
averaged curve. Its default value is NULL.
pAveMax
[output] if not NULL, pointer to buffer to receive max data for the
averaged curve. Its default value is NULL.

Return

Return OE_NOERROR if succeed, otherwise, non-zero error code is returned.

Examples

EX1

//This example assume the active window is a graph.
void ocmath_ave_replica_data_for_multiple_curves_ex1()
{
    GraphLayer gl = Project.ActiveLayer();
    if (!gl)
    {
        return;
    }
    
    int nPlots = gl.DataPlots.Count();
    
    OneCurveData* multiCurveData = (OneCurveData*) malloc(sizeof(OneCurveData)*nPlots);
    
    double* xx;
    double* yy;
    
    int nAveSize = 0;
    for(int ii =0 0; ii < nPlots; ii++)
    {
        DataPlot dp = gl.DataPlots(ii);        
        DataRange dr;
        vector vDatax, vDatay;
        if(dp.GetDataRange(dr))
        {
            DWORD dwPlotID;
            if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vDatay, &vDatax) < 0)
            {
                printf("get_plot_data failed GetData");
                return;
            }
        }
        int nSize = vDatay.GetSize();
    
        xx = (double*) malloc (sizeof(double) * nSize);
        yy = (double*) malloc (sizeof(double) * nSize);
    
        memcpy(xx, vDatax, sizeof(double)*nSize);
        memcpy(yy, vDatay, sizeof(double)*nSize);
        
        multiCurveData[ii].nSize = nSize;
        multiCurveData[ii].pX = xx;
        multiCurveData[ii].pY = yy;
        nAveSize += nSize;
    }
    
    vector vxAve(nAveSize);
    vector vyAve(nAveSize);
    vector vErr(nAveSize);
    vector<int> vCount(nAveSize);
    
    int nRet = ocmath_ave_replica_data_for_multiple_curves
                    (nPlots, multiCurveData, &nAveSize, vxAve, vyAve, vErr, AVMC_SE, vCount);
                        
    if( nRet!=OE_NOERROR )
    {
        printf("error code: %d\n", nRet);
        return;
    }
    
    vxAve.SetSize(nAveSize);
    vyAve.SetSize(nAveSize);
    vErr.SetSize(nAveSize);
    vCount.SetSize(nAveSize);
    
    for (ii = 0; ii < nPlots; ii++)
    {
        free(multiCurveData[ii].pX);
        free(multiCurveData[ii].pY);
    }
    free(multiCurveData);
    
    WorksheetPage wksPage;
    wksPage.Create();
    Worksheet wksAve = wksPage.Layers(0);
    wksAve.SetSize(-1, 2);
    wksAve.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
    wksAve.Columns(1).SetType(OKDATAOBJ_DESIGNATION_Y);        
    DataRange drOut;
    drOut.Add("X", wksAve, 0, 0, -1, 0);
    drOut.Add("Y", wksAve, 0, 1, -1, 1);
    drOut.SetData(&vyAve, &vxAve);
    gl.AddPlot(drOut, IDM_PLOT_SCATTER);
    
}

Remark

See Also

ocmath_ave_multiple_curves, ocmath_ave_multiple_curves_by_length_parameter

Header to Include

origin.h

Reference