matrixbase::GetRow

Description

Get the values of a matrix row and assign them to a vector.

Syntax

BOOL GetRow( vectorbase & vb, UINT wIndexRow )

Parameters

vb
[output] Vector used to get the matrix row values
wIndexRow
[input] Specifies the 0 based offset or row index of the row in the matrix

Return

Returns TRUE on success and FALSE on failure.

Examples

EX1

// Get a vector from a matrix row
void matrixbase_GetRow_ex1()
{    
    matrix<double> mat1 = {
        {1,  1,  1,  1},
        {2,  4,  6,  8},
        {3,  6,  9, 12}
    };
    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
    Mat1 = mat1;
    printf("  The input matrix is %s.\n",Mat1.GetName());

    vector v;
    int ii;
    
    int rc=Mat1.GetRow(v, 1);  // Get 2nd row(as the index starts 0) of Mat1 into v
    if(!rc) 
        printf("  Error: GetRow failed.\n");
    else
    {
        printf("  The gotten vector from 2nd row is:\n");
        for(ii = 0; ii < v.GetSize(); ii++) // Output cast elements of vectors
            printf("\t%g",v[ii]);
        printf("\n");
    }
}

Remark

Get the values of a matrix row and assign them to a vector. The row is specified by a 0 based row index. If the matrix row and vector do not have the same size then the vector is dynamically resized.

See Also

matrixbase::SetRow, matrixbase::GetColumn, matrixbase::SetColumn, matrixbase::GetAsVector, matrixbase::SetByVector

Header to Include

origin.h