2.2.3.9.27 matrixbase::GetColumn

Description

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

Syntax

BOOL GetColumn( vectorbase & vb, UINT wIndexCol )

Parameters

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

Return

Returns TRUE on success and FALSE on failure.

Examples

EX1

// Get a vector from a matrix column
void matrixbase_GetColumn_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.GetColumn(v, 2);  // Get 3rd column(as the index starts 0) of Mat1 into v
    if(!rc) 
        printf("  Error: GetColumn failed.\n");
    else
    {
        printf("  The gotten vector from 3rd column is:\n");
        for(ii = 0; ii < v.GetSize(); ii++) // Output cast elements of vectors
            printf("\t%g",v[ii]);
        printf("\n");
    }
    
    vector v2;
    rc=Mat1.GetColumn(v2, 4);  // Command Error! Index out of range.
    if(!rc) 
        printf("  Error: GetColumn failed.\n");
    else
    {
        printf("  The gotten vector from 3rd column is:\n");
        for(ii = 0; ii < v2.GetSize(); ii++) // Output cast elements of vectors
            printf("\t%g",v2[ii]);
        printf("\n");
    }
}

Remark

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

See Also

matrixbase::SetColumn, matrixbase::GetRow, matrixbase::SetRow, matrixbase::GetAsVector, matrixbase::SetByVector

Header to Include

origin.h