2.2.3.7.2 matrix::matrix

Description

Default constructor for matrix class.


Copy constructor for matrix class.


Constructor for matrix class that constructs a matrix object from a Dataset object.


Constructor for matrix class that constructs a matrix having a specific size.

Syntax

matrix( )


matrix( matrixbase & mbOriginal )


matrix( Dataset dsDataset )


matrix( UINT nNumRows, UINT nNumCols )


matrix( MatrixObject & mo, BOOL bWriteback = FALSE )

Parameters

mbOriginal
[input] Matrix that is copied


dsDataset
[input] Dataset object from which a matrix object is created


nNumRows
[input] Number of rows in constructed matrix
nNumCols
[input] Number of columns in constructed matrix


mo
[input] the source Matrix object
bWriteback
[input] if TRUE, it will write back the new values into the source on exiting the scope.

Return

Examples

EX1

int matrix_matrix_ex1()
{
    int ii, jj;
    matrix<int> mInts = {{1,2,3},{4,5,6},{7,8,9}};
    printf("mInts:\n");
    for(ii = 0; ii < mInts.GetNumRows(); ii++)
    {
        for(jj = 0; jj < mInts.GetNumCols(); jj++)
            printf("%d\t",mInts[ii][jj]);
        printf("\n");
    }

    matrix mDoublesByDefault = {{1.1,2.2,3.3},{4.4,5.5,6.6},{7.7,8.8,9.9}};
    printf("mDoublesByDefault:\n");
    for(ii = 0; ii < mDoublesByDefault.GetNumRows(); ii++)
    {
        for(jj = 0; jj < mDoublesByDefault.GetNumCols(); jj++)
            printf("%g\t",mDoublesByDefault[ii][jj]);
        printf("\n");
    }
    return 0;
}


EX2

int matrix_matrix_ex2()
{
    int ii, jj;
    matrix mA = {{1,2,3},{4,5,6},{7,8,9}};
    printf("mA:\n");
    for(ii = 0; ii < mA.GetNumRows(); ii++)
    {
        for(jj = 0; jj < mA.GetNumCols(); jj++)
            printf("%g\t",mA[ii][jj]);
        printf("\n");
    }

    matrix mB( mA );
    printf("mB Copy of mA:\n");
    for(ii = 0; ii < mB.GetNumRows(); ii++)
    {
        for(jj = 0; jj < mB.GetNumCols(); jj++)
            printf("%g\t",mB[ii][jj]);
        printf("\n");
    }
    return 0;
}


EX3

int matrix_matrix_ex3()
{
    // Assumes Data1_A data set with 9 elements exists in Origin
    int ii, jj;
    Dataset dsA("Book1",0);
    matrix mA( dsA ); // Construct a matrix from Data1_A
    mA.SetSize(3,3);
    printf("mA:\n");
    for(ii = 0; ii < mA.GetNumRows(); ii++)
    {
        for(jj = 0; jj < mA.GetNumCols(); jj++)
            printf("%g\t",mA[ii][jj]);
        printf("\n");
    }
    return 0;
}


EX4

int matrix_matrix_ex4()
{
    int ii, jj;
    matrix mA(4,5); // Construct an empty 4 x 5 matrix

    printf("mA:\n");
    for(ii = 0; ii < mA.GetNumRows(); ii++)
    {
        for(jj = 0; jj < mA.GetNumCols(); jj++)
        {
            mA[ii][jj] = ii + jj;    
            printf("%g\t",mA[ii][jj]);
        }
        printf("\n");
    }
    return 0;
}


EX5

// Have a matrix with the name "MBook1" in the project, with some values.
// After the function executes, the matrix will contain new values set inside
// the nested for-loops.
void    matrix_matrix_ex5()
{
    MatrixObject	mo("MBook1", 0); 
    matrix	m(mo, TRUE);
 
    int	nRows, nCols;
    if (m.GetSourceDim(nRows, nCols))
        printf("rows = %d\tcols=%d\n", nRows, nCols);
 
    // Change the size and set new values:
    m.SetSize(7, 9);
    for (int row = 0; row < m.GetNumRows(); row++)
    {
        for (int col = 0; col < m.GetNumCols(); col++)
            m[row][col] = (row + 1) * (col + 1);
    }
}

Remark

Initialize the matrix by copying the data from the source Matrix associated with

the MatrixObject mo. If bWriteback, on exiting the scope in which the matrix object was

declared, if writes back the values into the source Matrix. The original size of

the source matrix can be retrieved using the method GetSourceDim().

See Also

Header to Include

origin.h