matrixbase::SetSubMatrix
  SetSubMatrix 
  
  Description
  Set a subset of this matrix specified by 0 based column and row indices. The source and target matrices can have different types and different dimensions but the target matrix is never resized even if the source matrix is larger than the target. 
  Syntax
  
BOOL SetSubMatrix( matrixbase & mbSource, int c1 = 0, int r1 = 0 )
 
  Parameters
  
    - mbSource
 
    - [input] matixbase oject containing the subset to set
 
    - c1
 
    - [input] Begining column index in the target matrix, default is 0 (0 based offset)
 
    - r1
 
    - [input] Begining row index in the target matrix, default is 0 (0 based offset)
 
   
  Return
  Returns TRUE on successful exit or FALSE on failure. 
  Examples
  EX1 
  
void matrixbase_SetSubMatrix_ex1()
{
    int c1, r1;
    BOOL rc;
    
    matrix<double> matD = {
        {0,  0,  0,  0},
        {0,  0,  0,  0},
        {0,  0,  0,  0}
    };  // Destination matrix<double> to be applied the method
    
    matrix<int> matS = {
        {1,  2,  3},
        {5,  6,  7},
        {9, 10, 11}
    };  // Source matrix<int> to apply the method
    
    // Result matrix by this sample program will be:
    //  {0,  0,  0, 0}
    //  {0,  0,  1, 2}
    //  {0,  0,  5, 6}
    // Prepare the source matrix
    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
    Mat1 = matS;
    printf("  Source matrix is %s. Size=%dx%d.\n",
      Mat1.GetName(),Mat1.GetNumRows(),Mat1.GetNumCols());
    
    // Prepare a copy of the destination matrix
    MatrixPage MatPg2;
    MatPg2.Create("Origin");
    MatrixLayer MatLy2 = MatPg2.Layers(0);
    Matrix Mat2(MatLy2);
    Mat2 = matD;
    printf("  Original copy of the destination matrix is %s. Size=%dx%d.\n",
      Mat2.GetName(),Mat2.GetNumRows(),Mat2.GetNumCols());
    // Prepare the result destination matrix
    MatrixPage MatPg3;
    MatPg3.Create("Origin");
    MatrixLayer MatLy3 = MatPg3.Layers(0);
    Matrix Mat3(MatLy3);
    
    c1=2;
    r1=1;
    rc=matD.SetSubMatrix(matS, c1, r1);
    Mat3 = matD;
    
    printf("  Setting position: Row=%d, Col=%d.\n",r1+1,c1+1);
    if(!rc) 
        printf("  Error: Shrink failed.\n");
    else
        printf("  Result destination matrix is %s. Size=%dx%d.\n",
          Mat3.GetName(),Mat3.GetNumRows(),Mat3.GetNumCols());
}
  Remark
  See Also
  header to Include
  origin.h 
             |