2.2.4.49.1 XYRangeComplex::GetDataGetData
Description
Get xyz data from the datarange.
Syntax
BOOL GetData( vector<complex> & vy, vector & vx, int nIndex = 0 )
BOOL GetData( vector & vyReal, vector & vyImag, vector & vx, int nIndex = 0 )
Parameters
- vy
- [output]Dependent data
- vx
- [output]Independent data
- nIndex
- [input]index of the sub range
- vyReal
- [output]Real part of dependent data
- vyImag
- [output]Image part of dependent data
- vx
- [output]Independent data
- nIndex
- [input]index of the sub range
Return
TRUE if success, FALSE if fail.
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_GetData_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;
}
EX2
// 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 XYRangeComplex_GetData_ex2()
{
Worksheet wksSource;
wksSource.Create();
// Make sure there are at least 5 columns of data:
while ( wksSource.Columns.Count() < 5 )
wksSource.AddCol();
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);
}
DWORD dwRulesEx = DRR_GET_MISSING | DRR_BAD_WEIGHT_TREATMENT | DRR_COMPLEX | DRR_GET_DEPENDENT;
// Initialize XYRange:
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 3 * nNumData columns (X, YReal, and YImaginary for each data):
while ( wksOut.Columns.Count() < 3 * nNumData )
wksOut.AddCol();
// Get all the data and put them into the output worksheet:
for (int idata = 0; idata < nNumData; idata++)
{
vector vReal, vImag;
vector vx;
// Extract real and imaginary parts into separate vectors:
if ( !dr.GetData(vReal, vImag, vx, idata) )
{
out_str("Failed to get complex data!");
return;
}
Dataset dsReal(wksOut, 3 * idata + 1);
dsReal = vReal;
Dataset dsImag(wksOut, 3 * idata + 2);
dsImag = vImag;
// Set X-Values as well:
Dataset dX(wksOut, 3 * idata);
dX = vx;
}
return;
}
Remark
See Also
XYRangeComplex::SetData,
DataRange::GetData, DataRange::SetData
Header to Include
origin.h
|