Contents Previous Next Subchapters

Accessing Non-sequential Rows And Columns
Syntax matrix.row(row flag)
matrix.col(column flag)
matrix.blk(row flagcolumn flag)
See Also base , vector indices

Description
References the submatrix consisting of the specified rows and columns matrix. The row flag is a logical vector with length equal to the number of rows in matrix. It specifies which rows are included in the submatrix. The column flag is a logical vector with length equal to the number of columns in matrix. It specifies which columns are included in the submatrix.

Tutorial
You can use logical vectors to access submatrices. If you enter
     x = { [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]}
     rowflag = {true, false, true}
     x.row(rowflag)
O-Matrix will respond
     {
     [ 1 , 2 , 3 , 4 ]
     [ 9 , 10 , 11 , 12 ]
     }
If you continue by entering
     colflag = [false, true, false, true]
     x.col(colflag)
O-Matrix will respond
     {
     [  2 , 4 ]
     [  6 , 8 ]
     [ 10 , 12 ]
     }
If you then enter
     x.blk(rowflag, colflag)
O-Matrix will respond
     {
     [ 2 , 4 ]
     [ 10 , 12 ]
     }


You can also use logical row and column vectors to assign a value to a submatrix. The result has the type that corresponds to coercion between the type of the original matrix and the type of the submatrix. If you continue the previous example by entering
     x.blk(rowflag, colflag) = {[0, -1.1], [-1.1, 0]}
     print type(x), x
O-Matrix will respond
     real {
     [ 1 , 0 , 3 , -1.1 ]
     [ 5 , 6 , 7 , 8 ]
     [ 9 , -1.1 , 11 , 0 ]
     }
If you then enter
     x.row(rowflag) = {[4, 3, 2, 1], [12, 11, 10, 9]}
     x
O-Matrix will respond
     {
     [ 4 , 3 , 2 , 1 ]
     [ 5 , 6 , 7 , 8 ]
     [ 12 , 11 , 10 , 9 ]
     }
If you continue by entering
     x.col(colflag) = [{11, 6, 3}, {9, 8, 1}]
     print x
O-Matrix will respond
     {
     [ 4 , 11 , 2 , 9 ]
     [ 5 , 6 , 7 , 8 ]
     [ 12 , 3 , 10 , 1 ]
     }

Reference
You can use this syntax with logical expressions to select rows or columns of a matrix. For example, if you enter
     x = seq(4)
     y = seq(5)'
     z = x * y
     z.blk(x <= 3, y >= 3)
O-Matrix will respond
     {
     [ 3 , 4 , 5 ]
     [ 6 , 8 , 10 ]
     [ 9 , 12 , 15 ]
     }