Matrix Manipulation
[Modules]

This module include all functions for accessing, adding, and removing matrix elements. More...

Functions

double & ml_matrix::operator() (int row, int col)
 Accesses or assigns an element, resizes matrix if out of bounds.

double ml_matrix::get (int row, int col) const
 Accesses an element. Will not resize the matrix.

void ml_matrix::resize (int rows, int cols)
 Resizes the matrix, initializes new values to zero.

ml_matrixml_matrix::append_identity ()
 Adds an appropriately sized identity matrix to the existing matrix.

ml_matrix ml_matrix::sub_matrix (int from_row, int to_row, int from_col, int to_col) const
 Extracts a submatrix using a range of rows and columns.

ml_matrix ml_matrix::sub_matrix (int n_rows, int *rows, int n_cols, int *cols) const
 Extracts a submatrix using two arrays to select the rows and columns.

ml_matrix ml_matrix::sub_matrix (const ml_int_array &rows, const ml_int_array &cols) const
 Extracts a submatrix using two ml_int_arrays to select the rows and columns.

ml_matrix ml_matrix::get_row (int row) const
 Gets a single row.

ml_matrix ml_matrix::get_col (int col) const
 Gets a single column.

ml_matrix ml_matrix::get_row_set (int n_rows, int *rows) const
 Gets a set of rows defined by an array.

ml_matrix ml_matrix::get_row_set (const ml_int_array &rows) const
 Gets a set of rows defined by a ml_int_array.

ml_matrix ml_matrix::get_col_set (int n_cols, int *cols) const
 Gets a set of columns defined by an array.

ml_matrix ml_matrix::get_col_set (const ml_int_array &cols) const
 Gets a set of columns defined by a ml_int_array.

ml_matrix ml_matrix::sub_mat_row (int row, int n_cols, int *cols) const
 Returns a submatrix based on a row and an array of columns.

ml_matrix ml_matrix::sub_mat_row (int row, const ml_int_array &cols) const
 Returns a submatrix based on a row and a ml_int_array of columns.

ml_matrix ml_matrix::sub_mat_col (int n_rows, int *rows, int col) const
 Returns a submatrix based on an array of rows and a single column.

ml_matrix ml_matrix::sub_mat_col (const ml_int_array &rows, int col) const
 Returns a submatrix based on a ml_int_array of rows and a single column.

ml_matrix ml_matrix::extract_elements (const ml_matrix &elements)
 Extracts a set of elements as a column matrix.

ml_matrixml_matrix::delete_rows_cols (int n_rows, int *rows, int n_cols, int *cols)
 Deletes the rows and/or columns specified in the arrays.

ml_matrixml_matrix::delete_rows_cols (const ml_int_array &rows, const ml_int_array &cols)
 Deletes the rows and/or columns specified in the ml_int_arrays.

ml_matrixml_matrix::delete_rows_cols (int row, const ml_int_array &cols)
 Deletes the row and/or columns specified.

ml_matrixml_matrix::delete_rows_cols (const ml_int_array &rows, int col)
 Deletes the rows and/or column specified.

ml_matrixml_matrix::delete_rows_cols (int row, int col)
 Deletes the row and/or column specified.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, int n_rows, int *rows)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, const ml_int_array &rows)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, int n_rows, int *rows, int n_cols, int *cols)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, const ml_int_array &rows, const ml_int_array &cols)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, int row, int n_cols, int *cols)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, int row, const ml_int_array &cols)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, int n_rows, int *rows, int col)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_sub_matrix (const ml_matrix &m, const ml_int_array &rows, int col)
 Inserts the given matrix values into the specified locations.

ml_matrixml_matrix::inc_rows (const ml_matrix &a, int from_row, int to_row)
 Includes the specified rows from the given matrix into the original matrix.

ml_matrixml_matrix::inc_cols (const ml_matrix &m, int from_col, int to_col)
 Includes the specified columns from the given matrix into the original matrix.

ml_matrixml_matrix::inc_elements (const ml_matrix &values, const ml_matrix &elements)
 Incorporates a column matrix at the specified elements.

ml_matrixml_matrix::dup_rows (int num)
 Duplicates the rows of the matrix the specified number of times.

ml_matrixml_matrix::dup_cols (int num)
 Duplicates the columns of the matrix the specified number of times.

ml_matrixml_matrix::append (const ml_matrix &b)
 Returns a new matrix with the columns from the two matrices appended side by side.

ml_matrixml_matrix::stack (const ml_matrix &b)
 Returns a new matrix with the rows from the second matrix stacked below the rows of the first matrix.

ml_matrix append_identity (const ml_matrix &b)
 Adds an appropriately sized identity matrix to the existing matrix.

ml_matrix dup_rows (const ml_matrix &m, int num)
 Returns a new matrix with the specified matrix duplicated row-wise a given number of times.

ml_matrix dup_cols (const ml_matrix &m, int num)
 Returns a new matrix with the specified matrix duplicated column-wise a given number of times.

ml_matrix append (const ml_matrix &a, const ml_matrix &b)
 Returns a new matrix with the columns from the two matrices appended side by side.

ml_matrix stack (const ml_matrix &a, const ml_matrix &b)
 Returns a new matrix with the rows from the second matrix stacked below the rows of the first matrix.


Detailed Description

These functions handle standard matrix manipulations required for many operations. This group also includes sub-matrix operations, such as the addition and removal of rows and columns, and both horizontal and vertical concatenation of matrices.

Function Documentation

double & ml_matrix::operator() int  row,
int  col
[inherited]
 

Accesses or assigns an element, resizes matrix if out of bounds.

Parameters:
row The row of the element
col The column of the element
Returns:
Returns the requested element

double ml_matrix::get int  row,
int  col
const [inline, inherited]
 

Accesses an element.

Parameters:
row The row of the element
col The column of the element
Returns:
Returns the requested element

void ml_matrix::resize int  rows,
int  cols
[inherited]
 

Resizes the matrix, initializes new values to zero

Parameters:
rows The new number of rows
cols The new number of columns

ml_matrix & ml_matrix::append_identity  )  [inherited]
 

Adds an appropriately sized identity matrix to the existing matrix. Used for ml_matrix::inv().

Returns:
Returns the matrix with the identity appended.

ml_matrix ml_matrix::sub_matrix int  from_row,
int  to_row,
int  from_col,
int  to_col
const [inherited]
 

Extracts a submatrix using a range of rows and columns.

This function can return an error matrix of type ml_bad_range if the provided row and column ranges are out of bounds for the matrix.

Parameters:
from_row The starting row of the submatrix
to_row The ending row of the submatrix
from_col The starting column of the submatrix
to_col The ending column of the submatrix
Returns:
Returns the requested submatrix or an empty matrix if any parameters are invalid.

ml_matrix ml_matrix::sub_matrix int  n_rows,
int *  rows,
int  n_cols,
int *  cols
const [inherited]
 

Extracts a submatrix using two arrays to select the rows and columns.

This function can return an error matrix of type ml_bad_range if the provided row and column ranges are out of bounds for the matrix.

Parameters:
n_rows Number of rows in the row array
rows An array of rows to be used in creating the submatrix
n_cols Number of columns in the row array
cols An array of columns to be used in creating the submatrix
Returns:
Returns a submatrix!

ml_matrix ml_matrix::sub_matrix const ml_int_array rows,
const ml_int_array cols
const [inherited]
 

Extracts a submatrix using two ml_int_arrays to select the rows and columns. Function is included for MATLAB and backwards compatability.

This function can return an error matrix of type ml_bad_range if the provided row and column ranges are out of bounds for the matrix.

Parameters:
rows A ml_int_array of rows to be used in creating the submatrix
cols A ml_int_array of columns to be used in creating the submatrix
Returns:
Returns a submatrix.

ml_matrix ml_matrix::get_row int  row  )  const [inherited]
 

Gets a single row.

This function can return an error matrix of type ml_bad_index if the specified row is invalid for the matrix.

Parameters:
row The row to be gotten
Returns:
Returns a row matrix

ml_matrix ml_matrix::get_col int  col  )  const [inherited]
 

Gets a single column.

This function can return an error matrix of type ml_bad_index if the specified column is invalid for the matrix.

Parameters:
col The column to be gotten
Returns:
Returns a column matrix

ml_matrix ml_matrix::get_row_set int  n_rows,
int *  rows
const [inherited]
 

Gets a set of rows defined by an array.

This function can return an error matrix of type ml_bad_range if the number of rows is 0, or if any of the rows specified in the row array are invalid for this matrix.

Parameters:
n_rows The number of rows in the array
rows The array of rows to be used
Returns:
Returns a matrix constructed from the specified rows in the matrix.

ml_matrix ml_matrix::get_row_set const ml_int_array rows  )  const [inherited]
 

Gets a set of rows defined by a ml_int_array.

This function can return an error matrix of type ml_bad_range if the number of rows is 0, or if any of the rows specified in the row array are invalid for this matrix.

Parameters:
rows The ml_int_array of rows to be used
Returns:
Returns a matrix constructed from the specified rows in the matrix.

ml_matrix ml_matrix::get_col_set int  n_cols,
int *  cols
const [inherited]
 

Gets a set of columns defined by an array.

This function can return an error matrix of type ml_bad_range if the number of columns is 0, or if any of the columns specified in the row array are invalid for this matrix.

Parameters:
n_cols The number of columns in the array
cols The array of columns to be used
Returns:
Returns a matrix constructed from the specified columns in the matrix.

ml_matrix ml_matrix::get_col_set const ml_int_array cols  )  const [inherited]
 

Gets a set of columns defined by a ml_int_array.

This function can return an error matrix of type ml_bad_range if the number of columns is 0, or if any of the columns specified in the row array are invalid for this matrix.

Parameters:
cols The ml_int_array of columns to be used
Returns:
Returns a matrix constructed from the specified columns in the matrix.

ml_matrix ml_matrix::sub_mat_row int  row,
int  n_cols,
int *  cols
const [inherited]
 

Returns a submatrix based on a row and an array of columns.

This function can return an error matrix of type ml_bad_range if the specified row is invalid, if the number of columns is less than 1, or if any of the columns specified in the column array are out of bounds.

Parameters:
row The row to be used for the submatrix
n_cols The number of columns in the array
cols Array of columns to be used for the submatrix
Returns:
Returns a submatrix.

ml_matrix ml_matrix::sub_mat_row int  row,
const ml_int_array cols
const [inherited]
 

Returns a submatrix based on a row and a ml_int_array of columns.

This function can return an error matrix of type ml_bad_range if the specified row is invalid, if the number of columns is less than 1, or if any of the columns specified in the column array are out of bounds.

Parameters:
row The row to be used for the submatrix
cols ml_int_array of columns to be used for the submatrix
Returns:
Returns a submatrix.

ml_matrix ml_matrix::sub_mat_col int  n_rows,
int *  rows,
int  col
const [inherited]
 

Returns a submatrix based on an array of rows and a single column.

This function can return an error matrix of type ml_bad_range if the specified column is invalid, if the number of rows is less than 1, or if any of the rows specified in the column array are out of bounds.

Parameters:
n_rows Number of rows in the array
rows Array of rows to be used for the submatrix
col The column to be used for the submatrix
Returns:
Returns a submatrix

ml_matrix ml_matrix::sub_mat_col const ml_int_array rows,
int  col
const [inherited]
 

Returns a submatrix based on a ml_int_array of rows and a single column.

This function can return an error matrix of type ml_bad_range if the specified column is invalid, if the number of rows is less than 1, or if any of the rows specified in the column array are out of bounds.

Parameters:
rows ml_int_array of rows to be used for the submatrix
col The column to be used for the submatrix
Returns:
Returns a submatrix.

ml_matrix ml_matrix::extract_elements const ml_matrix elements  )  [inherited]
 

Extract a set of elements from this matrix to produce a column matrix.

Parameters:
elements An Nx2 matrix giving indices of the elements to be extracted. Such matrices are produced as results from the find function.
Returns:
An Nx1 colum matrix giving the values of the elements at the specified indices.

ml_matrix & ml_matrix::delete_rows_cols int  n_rows,
int *  rows,
int  n_cols,
int *  cols
[inherited]
 

Deletes the rows and/or columns specified in the arrays.

This function can return an error matrix of type ml_bad_range if any of the specified rows or columns are out of bounds.

Parameters:
n_rows The number of rows in the array of rows to be deleted
rows Array of rows to be deleted
n_cols The number of columns to be deleted
cols Array of columns to be deleted
Returns:
Returns the matrix with the specified rows and columns deleted

ml_matrix & ml_matrix::delete_rows_cols const ml_int_array rows,
const ml_int_array cols
[inherited]
 

Deletes the rows and/or columns specified in the ml_int_arrays.

This function can return an error matrix of type ml_bad_range if any of the specified rows or columns are out of bounds.

Parameters:
rows ml_int_array of rows to be deleted
cols ml_int_array of columns to be deleted
Returns:
Returns the matrix with the specified rows and columns deleted

ml_matrix & ml_matrix::delete_rows_cols int  row,
const ml_int_array cols
[inherited]
 

Deletes the row and/or columns specified.

This function can return an error matrix of type ml_bad_range if any of the specified rows or columns are out of bounds.

Parameters:
row Integer row to be deleted, default is zero(no row)
cols ml_int_array of columns to be deleted
Returns:
Returns the matrix with the specified row and columns deleted

ml_matrix & ml_matrix::delete_rows_cols const ml_int_array rows,
int  col
[inherited]
 

Deletes the rows and/or column specified.

This function can return an error matrix of type ml_bad_range if any of the specified rows or columns are out of bounds.

Parameters:
rows ml_int_array of rows to be deleted
col Integer column to be deleted, default is zero(no column)
Returns:
Returns the matrix with the specified rows and column deleted

ml_matrix & ml_matrix::delete_rows_cols int  row,
int  col
[inherited]
 

Deletes the row and/or column specified.

This function can return an error matrix of type ml_bad_range if either the specified row, or the specified column, are out of bounds.

Parameters:
row Integer row to be deleted, default is zero(no row)
col Integer column to be deleted, default is zero(no column)
Returns:
Returns the matrix with the specified row and column deleted

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
int  n_rows,
int *  rows
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if the number of columns in this matrix and m do not match, or if any specified row is out of bounds, or if the number of specified rows is greater than the number of rows in m.

Parameters:
m The matrix to be incorporated
n_rows Number of rows in the array of rows to be replaced
rows Array of rows to be replaced with the values in m
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
const ml_int_array rows
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if the number of columns in this matrix and m do not match, or if any specified row is out of bounds, or if the number of specified rows is greater than the number of rows in m.

Parameters:
m The matrix to be incorporated
rows ml_int_array of rows to be replaced with the values in m
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
int  n_rows,
int *  rows,
int  n_cols,
int *  cols
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if m contians fewer columns than n_cols, or fewer rows than n_rows, or if any specified row or column is less than 1.

Parameters:
m The matrix to be incorporated
n_rows Number of rows in the array of rows to be replaced
rows Array of rows to be replaced with the values in m
n_cols Number of columns in the array of columns to be replaced
cols Array of columns to be replaced with the values in m
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
const ml_int_array rows,
const ml_int_array cols
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if m contians fewer columns than the number given in the column array, or fewer rows than the number specified in the row array, or if any specified row or column is less than 1.

Parameters:
m The matrix to be incorporated
rows ml_int_array of rows to be replaced with the values in m
cols ml_int_array of columns to be replaced with the values in m
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
int  row,
int  n_cols,
int *  cols
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if m contians fewer columns than the number given in the column array, or if any specified row or column is less than 1.

Parameters:
m The matrix to be incorporated - should be a row matrix
row The row to be replaced
n_cols Number of columns in the array of columns to be replaced
cols Array of columns to be replaced with the values in m
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
int  row,
const ml_int_array cols
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if m contians fewer columns than the number given in the column array, or if any specified row or column is less than 1.

Parameters:
m The matrix to be incorporated - should be a row matrix
row The row to be replaced
cols ml_int_array of rows to be replaced with the values in m
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
int  n_rows,
int *  rows,
int  col
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if m contians fewer rows than the number given in the rows array, or if any specified row or column is less than 1.

Parameters:
m The matrix to be incorporated - should be a column matrix
n_rows Number of rows in the array of rows to be replaced
rows Array of rows to be replaced with the values in m
col The column to be replaced
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_sub_matrix const ml_matrix m,
const ml_int_array rows,
int  col
[inherited]
 

Inserts the given matrix values into the specified locations.

This function can return an error matrix of tyep ml_bad_range if m contians fewer rows than the number given in the row array, or if any specified row or column is less than 1.

Parameters:
m The matrix to be incorporated - should be a column matrix
rows ml_int_array of rows to be replaced with the values in m
col The column to be replaced
Returns:
Returns the matrix with the new values incorporated

ml_matrix & ml_matrix::inc_rows const ml_matrix m,
int  from_row,
int  to_row
[inherited]
 

Includes the specified rows from the given matrix into the original matrix.

This function can return an error matrix of type ml_bad_range if the specified rows are invalid, or describe a larger range than the number of rows in m, or if m contains more columns than this matrix.

Parameters:
m The source matrix for the row copy
from_row The beginning of the row range.
to_row The end of the row range.
Returns:
Returns the matrix with the new rows incorporated.

ml_matrix & ml_matrix::inc_cols const ml_matrix m,
int  from_col,
int  to_col
[inherited]
 

Includes the specified columns from the given matrix into the original matrix.

This function can return an error matrix of type ml_bad_range if the specified columns are invalid, or describe a larger range than the number of columns in m, or if m contains more rows than this matrix.

Parameters:
m The source matrix for the column copy
from_col The beginning of the column range.
to_col The end of the column range.
Returns:
Returns the matrix with the new columns incorporated.

ml_matrix & ml_matrix::inc_elements const ml_matrix values,
const ml_matrix elements
[inherited]
 

Incorporate the values in a column matrix into this matrix by storing the values in the elements indicated in the elements matrix.

Parameters:
values an Nx1 matrix giving the values to be incorporated
elements an Nx2 matrix giving the indices at which the values should be incorporated

ml_matrix & ml_matrix::dup_rows int  num  )  [inherited]
 

Duplicates the rows of the matrix the specified number of times.

Parameters:
num The number of times the rows should be duplicated.
Returns:
Returns the matrix after the duplication.

ml_matrix & ml_matrix::dup_cols int  num  )  [inherited]
 

Duplicates the columns of the matrix the specified number of times.

Parameters:
num The number of times the columns should be duplicated.
Returns:
Returns the matrix after the duplication.

ml_matrix & ml_matrix::append const ml_matrix b  )  [inherited]
 

Appends the 'b' matrix to the right side of the matrix.

This function can return an error matrix of type ml_size_mismatch if the number of rows in the matrices do not match.

Parameters:
b The matrix to form the right portion of the new matrix.
Returns:
Returns a new matrix with the columns from the two matrices appended side by side.

ml_matrix & ml_matrix::stack const ml_matrix b  )  [inherited]
 

Stacks the 'b' matrix below the matrix.

This function can return an error matrix of type ml_size_mismatch if the number of columns in the matrices do not match.

Parameters:
b The matrix to form the bottom portion of the new matrix.
Returns:
Returns a new matrix with the rows from the second matrix stacked below the rows of the first matrix.

ml_matrix append_identity const ml_matrix m  ) 
 

Non-member version of ml_matrix::append_identity().

Parameters:
m The matrix to which the identity matrix should be appended.
Returns:
Returns a new matrix with the identity matrix appended. The original matrix is not modified.

ml_matrix dup_rows const ml_matrix m,
int  num
 

Returns a new matrix with the specified matrix duplicated row-wise a given number of times.

Parameters:
m The matrix to be row-wise duplicated.
num The number of times the rows should be duplicated.
Returns:
Returns a new matrix with the specified matrix duplicated row-wise a given number of times.

ml_matrix dup_cols const ml_matrix m,
int  num
 

Returns a new matrix with the specified matrix duplicated column-wise a given number of times.

Parameters:
m The matrix to be column-wise duplicated.
num The number of times the columns should be duplicated.
Returns:
Returns a new matrix with the specified matrix duplicated column-wise a given number of times.

ml_matrix append const ml_matrix a,
const ml_matrix b
 

Appends the 'b' matrix to the right side of the 'a' matrix.

This function can return an error matrix of type ml_size_mismatch if the number of rows in the matrices do not match.

Parameters:
a The matrix to form the left portion of the new matrix.
b The matrix to form the right portion of the new matrix.
Returns:
Returns a new matrix with the columns from the two matrices appended side by side.

ml_matrix stack const ml_matrix a,
const ml_matrix b
 

Stacks the 'b' matrix below the 'a' matrix.

This function can return an error matrix of type ml_size_mismatch if the number of columns in the matrices do not match.

Parameters:
a The matrix to form the top portion of the new matrix.
b The matrix to form the bottom portion of the new matrix.
Returns:
Returns a new matrix with the rows from the second matrix stacked below the rows of the first matrix.