matrixbase::CopyTo

Description

Copy a subset of this matrix specified by 0 based column and row indices to a worksheet object

Syntax

BOOL CopyTo( Worksheet & wksTarget, int r1 = 0, int c1 = 0, int r2 = -1, int c2 = -1, int nr1Wks = 0, int nc1Wks = 0, BOOL bTransposed = TRUE, BOOL bSetColumnTypes = TRUE )

Parameters

wksTarget
[output] worksheet object to receive result
r1
[input] Begining row index, default is 0 (0 based offset)
c1
[input] Begining column index, default is 0 (0 based offset)
r2
[input] Ending row index, (inclusive) default -1 is GetNumRows -1 (0 based offset)
c2
[input] Ending column index, (inclusive) default -1 is GetNumCols -1 (0 based offset)
nr1Wks
[input] Begining row index of receive worksheet, default is 0 (0 based offset)
nc1Wks
[input] Begining column index of receive worksheet, default is 0 (0 based offset)
bTransposed
[input] if bTransposed = TRUE, Copy transposed matrix to worksheet
bSetColumnTypes
[input] if bSetColumnTypes = TRUE, will set worksheet column datatype same as matrix

Return

Returns TRUE on successful exit and FALSE on failure.

Examples

EX1

// Extract a submatrix into a worksheet area
void matrixbase_CopyTo_ex1()
{
    BOOL rc, bTransposed = FALSE, bSetColumnTypes = TRUE;
 
    matrix mat1 = { 
        {2,2,2,2,2},
        {2,1,1,1,2},
        {2,1,1,1,2},
        {2,2,2,2,2}                
    };
 
    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
    printf("  Original matrix %s has been created.\n",Mat1.GetName());
    Mat1 = mat1;
 
    Worksheet Wks1;
    Wks1.Create();
    Dataset myXDs(Wks1,0);
    Dataset myYDs(Wks1,1);
    String strWksName = Wks1.GetName();
 
    // Copy (2,2)-(3,4) submatrix to the worksheet from the 3rd row, 
    // change bTransposed or bSetColumnTypes to see the result
    rc=mat1.CopyTo(Wks1, 1, 1, 2, 3, 2, 0, bTransposed, bSetColumnTypes); 
 
    if(!rc) 
        printf("  Error: CopyTo on %s failed.\n",Mat1.GetName());
    else
        printf("  Extracted submatrix from (2,2) to (3,4) has been copied to the 3rd row of %s.\n",strWksName);
}

Remark

See Also

matrixbase::GetSubMatrix

header to Include

origin.h