2.2.4.49 XYRangeComplex


Name

XYRangeComplex

Remark

The XYRangeComplex class provides methods to get and set complex type XY dataset for matrix and worksheet window. Same as DataRange class, itself does not hold data, just keep the data range with page name, sheet name and row/column indices. One XYRangeComplex object allow containing multiple sub XY complex data ranges.

The XYRangeComplex class is derived from the XYRange, DataRange class from which it inherits methods and properties.

Hierarchy

Examples

EX1

// The function first creates a worksheet and puts some input data
// into it. Then it initializes XYRangeComplex such that it refers to the data
// in the worksheet.
// Then it creates the output worksheet, extracts the data from the input (i.e. source)
// worksheet using XYRangeComplex::GetData() method, and puts them into the output worksheet.
void    XYRangeComlex_ex1()
{
    Worksheet wksSource;
    wksSource.Create();
    // Make sure there are at least 5 columns of data:
    while ( wksSource.Columns.Count() < 5 )
        wksSource.AddCol();
    
    
    DWORD dwRulesEx = DRR_GET_MISSING | DRR_BAD_WEIGHT_TREATMENT;
    int nNumRows = 5;
    
    // Make columns 2 to 5 complex
    // and set some complex values into it:
    for (int col = 1; col <= 4; col++)
    {
        Column colObj = wksSource.Columns(col);
        colObj.SetFormat(OKCOLTYPE_NUMERIC);
        colObj.SetInternalData(FSI_COMPLEX);

        Dataset<complex>    ds(wksSource, col);
        ds.SetSize(nNumRows);
        for (int row = 0; row < nNumRows; row++)
        {
            double            rReal = pow(10, col) + row;
            double            rImag = (row + 1) * pow(10, col - 1);
            complex            cc(rReal, rImag);
            
            ds[row] = cc;
        }
    }
    
    // Set X-values into the first column:
    Dataset dsXSource(wksSource, 0);
    dsXSource.SetSize(nNumRows);
    for (int row = 0; row < nNumRows; row++)
    {
        dsXSource[row] = 0.1 * (row + 1);
    }

    // Initialize XYRangeComplex:
    XYRangeComplex                dr;
    dr.Add("X", wksSource, 0, 0, -1, 0);
    dr.Add("Y", wksSource, 0, 1, -1, 2);
    dr.Add("S", NULL);
    dr.Add("X", wksSource, 0, 0, -1, 0);
    dr.Add("Y", wksSource, 0, 3, -1, 3);
    dr.Add("Y", wksSource, 0, 4, -1, 4);
    
    int    nNumData = dr.GetNumData(dwRulesEx);
    
    // Create worksheet for putting the extracted data into:
    Worksheet wksOut;
    wksOut.Create();
    // Make sure the worksheet has 2 * nNumData columns:
    while ( wksOut.Columns.Count() < 2 * nNumData )
        wksOut.AddCol();
    
    // Get all the data and put them into the output worksheet:
    for (int idata = 0; idata < nNumData; idata++)
    {
        vector<complex>        vc;
        vector                vx;
        if ( !dr.GetData(vc, vx, idata) )
        {
            out_str("Failed to get complex data!");
            return;
        }
        
        // Set the column for complex values to be complex:
        int                colIndexComplex = 2 * idata + 1;
        Column            colObj = wksOut.Columns(colIndexComplex);
        colObj.SetFormat(OKCOLTYPE_NUMERIC);
        colObj.SetInternalData(FSI_COMPLEX);
        
        Dataset<complex>    dc(wksOut, colIndexComplex);
        dc = vc;
        
        // Set X-Values as well:
        Dataset                dX(wksOut, 2 * idata);
        dX = vx;
    }
    
    return;
}

Header to Include

origin.h

Reference

Members

Name Brief Example
GetData Get xyz data from the datarange Examples
SetData Update xyz data with new data in vectors Examples