Inspection and Assignment
[Modules]

This group of functions includes comparison operators, functions to reassign matrix values, and inspection functions such as min() and max(). More...

Functions

int ml_matrix::is_empty () const
 Checks for an empty matrix.

int ml_matrix::operator== (const ml_matrix &m) const
 Tests two matrices for equality.

int ml_matrix::operator!= (const ml_matrix &m) const
 Inequality function. Returns the opposite of the equality function.

ml_matrix ml_matrix::find (ml_comparison op, double target) const
 Determines the indices of all elements for which a specified comparison and value are true.

void ml_matrix::sort (int direction=0)
 Sorts all the elements of the matrix. Ascending order is the default, pass a non-zero value for descending sort.

ml_matrix ml_matrix::sort_indices (int direction=0) const
 Returns the indices that produce a sorted version of the original matrix.

void ml_matrix::permute (const ml_matrix &elements)
 Permute a matrix based on a return from sort_indices.

ml_matrix ml_matrix::sum_rows () const
 Returns a column matrix containing the sums of the values from each row.

ml_matrix ml_matrix::sum_cols () const
 Returns a row matrix containing the sums of the values from each column.

ml_matrix ml_matrix::max () const
 Finds the value and indices of the largest element in the matrix.

ml_matrix ml_matrix::row_max () const
 Finds the maximum value and index for each row in the matrix.

ml_matrix ml_matrix::col_max () const
 Finds the maximum value and index for each column in the matrix.

ml_matrix ml_matrix::min () const
 Finds the value and indices of the smallest element in the matrix.

ml_matrix ml_matrix::row_min () const
 Finds the minimum value and index for each row in the matrix.

ml_matrix ml_matrix::col_min () const
 Finds the minimum value and index for each column in the matrix.

ml_matrix ml_matrix::interpolate (int col, double value) const
 Linear interpolation based on the specified column.

int ml_matrix::rows () const
 Returns the number of rows in the matrix.

int ml_matrix::cols () const
 Returns the number of columns in the matrix.

ml_matrixml_matrix::operator= (const ml_matrix &m)
 Sets matrix equal to another matrix.

ml_matrixml_matrix::operator= (const char *s)
 Assigns the MATLAB string representation of a matrix to this matrix.

void ml_matrix::zero ()
 Replaces all values in the matrix with zero.

void ml_matrix::ones ()
 Replaces all values in the matrix with one.

void ml_matrix::set_val (double v)
 Replaces all values in the matrix with the given value.

void ml_matrix::set_val (const ml_matrix &elements, double v)
 Replaces all values at the specified indices in the matrix with a given value.

ml_matrixml_matrix::apply (double(*func)(double))
 Applies a specified function to every element in the matrix.

void ml_matrix::apply_to_elements (const ml_matrix &elements, double(*func)(double))
 Applies a specified function to a subset of the elements in the matrix.

void ml_matrix::identity ()
 Changes the matrix to an identity matrix.

void ml_matrix::rand_seed (double seed)
 Sets the random seed for this matrix.

void ml_matrix::rand ()
 Replaces all values in the matrix with randomly generated values.

void ml_matrix::randn (double std_dev)
 Replaces all values in the matrix with randomly generated values, given a standard deviation.

ml_matrix sort (const ml_matrix &m, int direction=0)
 Sorts all the elements of the matrix. Ascending order is the default, pass a non-zero value for descending sort.

ml_matrix apply (const ml_matrix &m, double(*func)(double))
 Applies a specified function to every element in the matrix.


Variables

int ml_matrix::error
 The current error status of the matrix.


Detailed Description

A group of functions for comparing matrices and elements, looking at the matrix as a whole, and using the standard "=" operator for assignment.

Function Documentation

int ml_matrix::is_empty  )  const [inherited]
 

Checks for an empty matrix.

Returns:
Returns a 1 if the matrix is empty, 0 if it is not.

int ml_matrix::operator== const ml_matrix m  )  const [inherited]
 

Tests two matrices for equality.

Parameters:
m Matrix to compare with the original matrix
Returns:
Returns 1 if all elements of the matrix are equivalent, 0 otherwise

int ml_matrix::operator!= const ml_matrix m  )  const [inherited]
 

Inequality function. Returns the opposite of the equality function.

Parameters:
m The matrix to compare with the original matrix
Returns:
Returns 1 if the matrices are not equal, 0 if they are equal.

ml_matrix ml_matrix::find ml_comparison  op,
double  target
const [inherited]
 

Determines the indices of all elements of the matrix having the specified comparison relationship with a given value. The index information will be returned in a new matrix with two columns and the number of rows equal to the total number of elements for which the comparison is true, with each row containing a (row, column) pair indicating the location of the corresponding element.

See also:
ml_comparison
Parameters:
op A comparison operator of type ml_comparison.
target Double value to compare all elements to.
Returns:
Returns a ml_matrix with the indices of all elements for which the operator was true.

void ml_matrix::sort int  direction = 0  )  [inherited]
 

Sorts all the elements of the matrix. Ascending order is the default, pass a non-zero value for descending sort.

Parameters:
direction The sort direction: 0 (default) for ascending, non-zero for descending.

ml_matrix ml_matrix::sort_indices int  direction = 0  )  const [inherited]
 

Determines the indices of matrix elements either ordered ascending or descending. The orginal matrix will not be changed. The index information will be returned in a new matrix with two columns and the number of rows equal to the total number of elements in the matrix, with each row containing a (row, column) pair indicating the location of the corresponding element.

Parameters:
direction The sort direction: 0 (default) for ascending, non-zero for descending.
Returns:
Returns a n x 2 matrix with (row,column) index pairs for the elements ordered by value.

void ml_matrix::permute const ml_matrix elements  )  [inherited]
 

Permute this matrix based on an elements matrix in the form of the return from sort_indices().

Parameters:
elements An Nx2 matrix, where N = rows()*cols()

ml_matrix ml_matrix::sum_rows  )  const [inherited]
 

Returns a column matrix containing the sums of the values from each row.

Returns:
Returns a column matrix.

ml_matrix ml_matrix::sum_cols  )  const [inherited]
 

Returns a row matrix containing the sums of the values from each column.

Returns:
Returns a row matrix.

ml_matrix ml_matrix::max  )  const [inherited]
 

Finds the value and location of the largest element in the matrix.

Returns:
Returns a 1 x 3 matrix containing the largest value in the matrix, followed by the row and column at which it is located.

ml_matrix ml_matrix::row_max  )  const [inherited]
 

Finds the maximum value and index for each row in the matrix.

Returns:
A matrix containing the maximum value and index for each row in the matrix.

ml_matrix ml_matrix::col_max  )  const [inherited]
 

Finds the maximum value and index for each column in the matrix.

Returns:
A matrix containing the maximum value and index for each column in the matrix.

ml_matrix ml_matrix::min  )  const [inherited]
 

Finds the value and location of the smallest element in the matrix.

Returns:
Returns a 1 x 3 matrix containing the smallest value in the matrix, followed by the row and column at which it is located.

ml_matrix ml_matrix::row_min  )  const [inherited]
 

Finds the minimum value and index for each row in the matrix.

Returns:
A matrix containing the minimum value and index for each row in the matrix.

ml_matrix ml_matrix::col_min  )  const [inherited]
 

Finds the minimum value and index for each column in the matrix.

Returns:
A matrix containing the minimum value and index for each column in the matrix.

ml_matrix ml_matrix::interpolate int  col,
double  value
const [inherited]
 

Interpolate to find the row associated with a given value for a specifed column.

This function can return an error matrix of type ml_bad_index if the requested interpolation value is too high or too low for interpolation.

Parameters:
col The column of which the value would be a member
value The value to find data for
Returns:
The data for the value, created via interpolation if necessary

int ml_matrix::rows  )  const [inline, inherited]
 

Gets the number of rows in the matrix

Returns:
Returns the number of rows

int ml_matrix::cols  )  const [inline, inherited]
 

Gets the number of columns in the matrix

Returns:
Returns the number of columns

ml_matrix & ml_matrix::operator= const ml_matrix m  )  [inherited]
 

Sets matrix equal to another matrix

Parameters:
m the matrix to be made equal to
Returns:
Returns this matrix, after being set equal

ml_matrix & ml_matrix::operator= const char *  s  )  [inherited]
 

Assigns the MATLAB string representation of a matrix to this matrix

Parameters:
s String representation of matrix
Returns:
Returns the new matrix

void ml_matrix::zero  )  [inherited]
 

Replaces all values in the matrix with zero.

Returns:
Returns the matrix with all values set to zero.

void ml_matrix::ones  )  [inherited]
 

Replaces all values in the matrix with one.

Returns:
Returns the matrix with all values set to one.

void ml_matrix::set_val double  v  )  [inherited]
 

Replaces all values in the matrix with the given value.

Parameters:
v New value for all elements of the matrix.

void ml_matrix::set_val const ml_matrix elements,
double  v
[inherited]
 

Replaces all values at the specified indices in the matrix with a given value

Parameters:
elements The matrix giving the elements to replace. Nx2, in the format as described by the return value to ml_matrix::find()
v The replacement value.

ml_matrix & ml_matrix::apply double(*  func)(double)  )  [inherited]
 

Applies a specified function to every element in the matrix.

Parameters:
func A function accepting a double parameter and returning a double value.
Returns:
Returns the matrix after the operation has be applied.

void ml_matrix::apply_to_elements const ml_matrix elements,
double(*  func)(double)
[inherited]
 

Applies a function to a set of elements in the matrix

Parameters:
elements The matrix giving the elements to apply the function to. Nx2, in the format as described by the return value to ml_matrix::find()
func The function to apply

void ml_matrix::identity  )  [inherited]
 

Changes the matrix to an identity matrix.

void ml_matrix::rand_seed double  nseed  )  [inherited]
 

Sets the random seed for this matrix.

Parameters:
nseed The seed this matrix will use for generating random numbers.

void ml_matrix::rand  )  [inherited]
 

Replaces all values in the matrix with randomly generated values.

void ml_matrix::randn double  std_dev  )  [inherited]
 

Replaces all values in the matrix with randomly generated values, given a standard deviation.

Parameters:
std_dev Standard deviation to be used for generating random numbers.

ml_matrix sort const ml_matrix m,
int  direction
 

Returns a new matrix, equal to the specified matrix, but with all the elements sorted. Ascending order is the default, pass a non-zero value for descending sort. Does not change the original matrix.

Parameters:
m The matrix to be copied and sorted.
direction The sort direction: 0 (default) for ascending, non-zero for descending.
Returns:
A new matrix with the same dimensions and values as the old matrix, but with the values ordered.

ml_matrix apply const ml_matrix m,
double(*  func)(double)
 

Applies a specified function to every element in the matrix. The matrix is not modified, instead a new matrix is created and returned following the operation.

Parameters:
m The matrix to which the operation should be applied.
func A function accepting a double parameter and returning a double value.
Returns:
Returns a new matrix.


Variable Documentation

int ml_matrix::error [inherited]
 

The current error status of the matrix, one of the enumeration ml_error_codes. This value will always be equal to ml_no_error unless some operation has resulted in a specific error.