DataRange::SetData
SetData
Description
It sets a matrix data into the data referred to by the DataRange object.
Syntax
BOOL SetData( const matrixbase & m, int index = 0, BOOL bUndo = FALSE, DWORD dwDRSOpts = 0 )
BOOL SetData( vectorbase & pv, BOOL bUndo = FALSE, int index = 0, DWORD dwDRSOpts = 0 )
BOOL SetData( vector * pvY, vector * pvX, BOOL bUndo = FALSE, int index = 0 )
BOOL SetData( vector * pvZ, vector * pvY, vector * pvX, BOOL bUndo = FALSE, int index = 0 )
Parameters
- m
- [input]the source data
- index
- [input]data index in case DataRange refers to multiple matrices.
- bUndo
- [input]whether the action should be undoable.
- dwDRSOpts
- [input] possible values:
- DRS_COMPLEX - to set complex (if m is complex)
- pv
- [input]The data want to set into data range.
- bUndo
- [input]whether the action should be undoable.
- index
- [input]data index
- dwDRSOpts
- [input] possible values:
- DRS_COMPLEX - to set complex (if m is complex)
- pvY
- [input]
- pvX
- [input]
- bUndo
- [input]whether the action should be undoable.
- index
- [input]data index
- pvZ
- [input]
- pvY
- [input]
- pvX
- [input]
- bUndo
- [input]whether the action should be undoable.
- index
- [input]data index
Return
TRUE if success.
True if Successful
True if Successful
True if Successful
Examples
EX1
// For this example to run, have two matrices, MBook1 and MBook2, and put some data
// into MBook1.
// The sample will transfer the data from MBook1 to MBook2.
void DataRange_SetData_Ex1()
{
Matrix mat("MBook1");
if (!mat)
return;
string strRangeSet = "[MBook2]MSheet1!1";
DataRange drSet;
int nn = drSet.AddInput(strRangeSet);
if (nn < 0)
return; // failed. Perhaps Matrix2 does not exist.
BOOL nRet = drSet.SetData(mat);
out_int("nRet = ", nRet);
return;
}
EX2
// The data of the worksheet's first column will multiply by 10
void DataRange_SetData_Ex2(int nXCol = 0)
{
Worksheet wks;
wks.Create();
if( wks )
{
while(wks.Columns(0))
wks.DeleteCol(0);
wks.AddCol("A");
double rr;
for (int i=0;i<10;i++)
{
rr=rnd();
wks.SetCell(i,0,rr*100);
}
DataRange dr;
dr.Add("X", wks, 0, nXCol, -1, nXCol);
vector vX;
DWORD dwPlotID;
dr.GetData(DRR_GET_MISSING | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vX);
vX *= 10.0;
dr.SetData(vX); // This SetData takes a reference to a vector not a pointer to vector
}
}
EX3
// This example assumes a worksheet with two columns is active.
//Fill Col(A) and Col(B) of the worksheet with data.
void DataRange_SetData_Ex3(int nXCol = 0, int nYCol = 1)
{
Worksheet wks = Project.ActiveLayer();
if( !wks )
return;
vector vX, vY;
vX.Data(1, 10, 1);
vY = vX + 10;
DataRange dr;
dr.Add(wks, nXCol, "X");
dr.Add(wks, nYCol, "Y");
dr.SetData(&vY, &vX);
}
EX4
// This example will copy the data of all the three columns' even row to another columns
void DataRange_SetData_Ex4(int nXCol = 0, int nYCol = 1, int nZCol = 2)
{
Worksheet wks;
wks.Create();
if( wks )
{
while(wks.Columns(0))
wks.DeleteCol(0);
wks.AddCol("A");
wks.AddCol("B");
wks.AddCol("C");
double rr;
for(int j=0;j<3;j++)
{
for (int i=0;i<10;i++)
{
rr=rnd();
wks.SetCell(i,j,rr*100);
}
}
DataRange drIn;
drIn.Add("X", wks, 0, nXCol, -1, nXCol);
drIn.Add("Y", wks, 0, nYCol, -1, nYCol);
drIn.Add("Z", wks, 0, nZCol, -1, nZCol);
vector vX, vY, vZ;
DWORD dwRules = DRR_GET_MISSING | DRR_GET_Z_DEPENDENT | DRR_NO_FACTORS;
DWORD dwPlotID;
// Use this overloaded version of GetData to find out how many rows of XYZ data
drIn.GetData(dwRules, 0, &dwPlotID, NULL, &vZ, &vX, NULL, NULL, NULL, NULL, NULL, NULL, &vY);
int iSizeIn = vX.GetSize();
int iSizeOut = iSizeIn/2 + 1;
vector<int> vIndicesIn;
vIndicesIn.Data(0, iSizeIn - 1, 2);
// Use this overloaded version of GetData with vIndicesIn to extract odd rows to new columns
drIn.GetData(dwRules, 0, vIndicesIn, vZ, vX, vY);
string strColDesigs = wks.GetColDesignations();
nXCol = wks.AddCol();
nYCol = wks.AddCol();
nZCol = wks.AddCol();
strColDesigs += "XYZ";
wks.SetColDesignations(strColDesigs);
DataRange drOut;
drOut.Add("X", wks, 0, nXCol, -1, nXCol);
drOut.Add("Y", wks, 0, nYCol, -1, nYCol);
drOut.Add("Z", wks, 0, nZCol, -1, nZCol);
drOut.SetData(&vZ, &vY, &vX);
}
}
Remark
See Also
Curve::Curve,curvebase::AttachX,DataRange::GetData,DataRange::GetMaskedData,DataRange::GetMissingData,DataRange::GetNumData
header to Include
origin.h
|