Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Matrix_class Wizardsneverdie TwoTank mbed_multiplex_matrix ... more
Revision 1:48f417da268e, committed 2011-09-26
- Comitter:
- Yo_Robot
- Date:
- Mon Sep 26 03:23:35 2011 +0000
- Parent:
- 0:3abd8c2d7c34
- Child:
- 2:493402568a5e
- Commit message:
- Matrix Class v1.02 - Fixed bugs and typos. Later work will add more functions. This is a replacement for the previous version. Use this one not the old one.
Changed in this revision
| Matrix.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Matrix.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Matrix.cpp Fri Sep 23 21:12:17 2011 +0000
+++ b/Matrix.cpp Mon Sep 26 03:23:35 2011 +0000
@@ -1,76 +1,75 @@
#include "mbed.h"
#include "Matrix.h"
-// Rows by Cols Matrix Constructor
-Matrix::Matrix(int Cols, int Rows): _Cols(Cols), _Rows(Rows)
+
+/// Rows by Cols Matrix Constructor
+Matrix::Matrix(int Rows, int Cols): _nCols(Cols), _nRows(Rows)
{
- _matrix.resize(_Rows);
- for( int i = 0; i < _Rows; i++ )
- _matrix[i].resize(_Cols);
+ _matrix.resize(_nRows);
+ for( int i = 0; i < _nRows; i++ )
+ _matrix[i].resize(_nCols);
}
-
-// Defines the same parameters as 'base' Matrix
-Matrix::Matrix(const Matrix &base): _Cols(base._Cols), _Rows(base._Rows)
+/// Defines the same parameters as 'base' Matrix
+Matrix::Matrix(const Matrix &base): _nCols(base._nCols), _nRows(base._nRows)
{
- _matrix.resize(_Rows);
- for( int i = 0; i < _Rows; i++ )
- _matrix[i].resize(_Cols);
+ _matrix.resize(_nRows);
+ for( int i = 0; i < _nRows; i++ )
+ _matrix[i].resize(_nCols);
}
-
-// Square Matrix Constructor
-Matrix::Matrix(int square): _Cols(square), _Rows(square)
+/// Square Matrix Constructor
+Matrix::Matrix(int square): _nCols(square), _nRows(square)
{
- _matrix.resize(_Rows);
- for( int i = 0; i < _Rows; i++ )
- _matrix[i].resize(_Cols);
+ _matrix.resize(_nRows);
+ for( int i = 0; i < _nRows; i++ )
+ _matrix[i].resize(_nCols);
}
-
-// Default Constructor
+/// Default Constructor
Matrix::Matrix(){/*Intentionally left Blank*/}
-//***** OPERATORS ****//
+/************************************************************************/
-// Overloaded Asign Operator
+
+/// Overloaded Asign Operator. Resizes Matrix
Matrix& Matrix::operator = ( const Matrix &rightM )
{
if( *this != rightM )
{
- this->_Rows = rightM._Rows;
- this->_Cols = rightM._Cols;
+ this->_nRows = rightM._nRows;
+ this->_nCols = rightM._nCols;
- this->_matrix.resize( rightM._Rows );
- for( int i = 0; i < rightM._Rows; i++ )
- this->_matrix [i].resize(rightM._Cols);
+ this->_matrix.resize( rightM._nRows );
+ for( int i = 0; i < rightM._nRows; i++ )
+ this->_matrix [i].resize(rightM._nCols);
- for( int i = 0; i < _Rows; i++ )
- for( int j = 0; j < _Cols; j++ )
+ for( int i = 0; i < _nRows; i++ )
+ for( int j = 0; j < _nCols; j++ )
this->_matrix[i][j] = rightM._matrix[i][j];
return *this;
- }
- else
- {
+
+ }else{
+
Matrix ret (*this);
return ret;
}
}
-
+/// Comapre element by element
bool Matrix::operator == ( const Matrix& rightM )
{
- if( _Rows == rightM._Rows && _Cols == rightM._Cols )
+ if( _nRows == rightM._nRows && _nCols == rightM._nCols )
{
bool equal = false;
- for( int i = 0; i < _Rows; i++ )
- for( int j = 0; j < _Cols; j++ )
+ for( int i = 0; i < _nRows; i++ )
+ for( int j = 0; j < _nCols; j++ )
if( _matrix[i][j] != rightM._matrix[i][j] )
equal = equal || true;
@@ -80,54 +79,56 @@
}
+/// Calls for '==' operator
bool Matrix::operator != ( const Matrix &rightM )
{
return !( *this == rightM );
}
+/// Matrices must be same size.
+/// Element by element adition.
Matrix& Matrix::operator +=(const Matrix& rightM)
{
- if( _Rows == rightM._Rows && _Cols == rightM._Cols )
+ if( _nRows == rightM._nRows && _nCols == rightM._nCols )
{
- for( int i = 0; i < _Rows; i++ )
- for( int j = 0; j < _Cols; j++ )
+ for( int i = 0; i < _nRows; i++ )
+ for( int j = 0; j < _nCols; j++ )
_matrix[i][j] += rightM._matrix[i][j];
return *this;
}else{
-
- printf( "\nERROR\nDiferent Dimensions @ += Assignment\n" );
-
- // Code below doesn't work! I dunno why. But anyway at this point
- // the program should break anyway.
- //
- //Matrix::Matrix error( 4 );
- //error.Clear();
- //return error;
-
+ printf( "\n\nERROR\nDiferent Dimensions @ += \n" );
+ // Matrix error(4);
+ // error.Clear();
+ // return error;
}
}
+/// Matrices must be same size.
+/// Element by element Substraction
Matrix& Matrix::operator -=(const Matrix& rightM)
{
- if( _Rows == rightM._Rows && _Cols == rightM._Cols )
+ if( _nRows == rightM._nRows && _nCols == rightM._nCols )
{
- for( int i = 0; i < _Rows; i++ )
- for( int j = 0; j < _Cols; j++ )
+ for( int i = 0; i < _nRows; i++ )
+ for( int j = 0; j < _nCols; j++ )
_matrix[i][j] -= rightM._matrix[i][j];
return *this;
}else{
- printf( "\nERROR\nDiferent Dimensions @ -= Assignment\n" );
-
- // return rightM;
+ printf( "\n\nERROR\nDiferent Dimensions @ -= \n" );
+ //Matrix error(4);
+ //error.Clear();
+ //return error;
}
}
+
+/// Element by element Adition. Must be same sizes
const Matrix Matrix::operator +(const Matrix& rightM)
{
Matrix result = *this;
@@ -135,6 +136,8 @@
return result;
}
+
+/// Element by element Substraction. Must be same sizes
const Matrix Matrix::operator -(const Matrix& rightM)
{
Matrix result = *this;
@@ -142,60 +145,41 @@
return result;
}
-//------------------------------------------
-
-//*** Method that return MATRIX objects ***//
-
+/************************************************************************/
-Matrix Matrix::GetRow(Matrix mat, int Row)
+/// Returns true if matrix is full of zeros
+bool Matrix::isZero()
{
- if( Row > mat._Rows )
- {
- printf( "WARNING: Row out of dimmensions @ GetRow().\nEmpty Matrix Returned\n" );
- Matrix err( 1 , mat._Cols );
- err.Clear();
- return err;
- }else{
-
- Matrix SingleRow( 1 , mat._Cols );
-
- for( int i = 0; i < mat._Cols; i++ )
- SingleRow._matrix[0][i] = mat._matrix[Row][i];
-
- return SingleRow;
- }
+ bool zero = false;
+ for( int i = 0; i < this->_nRows; i++ )
+ for( int j = 0; j < this->_nCols; j++ )
+ if( this->_matrix[i][j] != 0 )
+ zero = zero || true;
+ return !zero;
}
-
-Matrix Matrix::GetCol(Matrix mat, int Col)
+/// Returns true if Matrix is Single Row ot Single Column.
+bool Matrix::isVector()
{
- if( Col > mat._Cols )
- {
- printf( "WARNING: Column out of dimmensions @ GetCol.\nEmpty matrix returned\n" );
- Matrix err( mat._Rows , 1 );
- err.Clear();
- return err;
- }else{
-
- Matrix SingleCol( mat._Rows, 1 );
- for(int i = 0; i < mat._Rows; i++ )
- SingleCol._matrix[i][0] = mat._matrix[i][Col];
- return SingleCol;
- }
+ if( this->_nRows == 1 || this->_nCols == 1 )
+ return true;
+ else
+ return false;
}
+/*************************************************************************/
-
+/// Returns all elements in Matrix as a single Row vector.
Matrix Matrix::ToPackedVector()
{
- Matrix Shattered( ( this->_Rows * this->_Cols ) , 1 );
+ Matrix Shattered( ( this->_nRows * this->_nCols ) , 1 );
int cont = 0;
- for( int i = 0; i < this->_Rows; i++ )
+ for( int i = 0; i < this->_nRows; i++ )
{
- for( int j = 0; j < this->_Cols; j++ )
+ for( int j = 0; j < this->_nCols; j++ )
{
Shattered._matrix[0][cont] = this->_matrix[i][j];
cont++;
@@ -204,60 +188,33 @@
return Shattered;
}
-//----------------------------------------------------
-//*** Method returning BOOLEAN ***//
-
-
-
-
-bool Matrix::isZero()
-{
- bool zero = false;
- for( int i = 0; i < this->_Rows; i++ )
- for( int j = 0; j < this->_Cols; j++ )
- if( this->_matrix[i][j] != 0 )
- zero = zero || true;
- return !zero;
-}
+/***************************************************************************/
-
-
-bool Matrix::isVector()
+/// Test elment-by-element. Prints detailed error.
+bool Matrix::Equals( const Matrix mat1, const Matrix mat2 )
{
- if( this->_Rows == 1 || this->_Cols == 1 )
- return true;
- else
- return false;
-}
-
-//-------------------------------------
-
-//*** Static Methods ***//
-
-const bool Matrix::Equals( Matrix mat1, Matrix mat2 )
-{
- if( mat1._Cols == mat2._Cols && mat1._Rows == mat2._Rows )
+ if( mat1._nCols == mat2._nCols && mat1._nRows == mat2._nRows )
{
bool equal = false;
- for( int i = 0; i < mat1._Rows; i++ )
- for( int j = 0; j < mat1._Cols; j++ )
+ for( int i = 0; i < mat1._nRows; i++ )
+ for( int j = 0; j < mat1._nCols; j++ )
if( mat1._matrix[i][j] != mat2._matrix[i][j] )
equal = equal || true;
return !equal;
}else{
- printf( "ERROR: Diferent Size Matrices!\n" );
- printf( "mat1._Rows = %u\nmat1._Cols = %u\n",mat1._Rows, mat1._Cols );
- printf( "mat2._Rows = %u\nmat2._Cols = %u\n",mat2._Rows, mat2._Cols );;
+ printf( "\n\nERROR:\nDiferent Size Matrices!\n" );
+ printf( "mat1._nRows = %u\nmat1._nCols = %u\n",mat1._nRows, mat1._nCols );
+ printf( "mat2._nRows = %u\nmat2._nCols = %u\n",mat2._nRows, mat2._nCols );
return false;
}
}
-
+/// To Implicitly create a Single Column Matrix.
Matrix Matrix::CreateColumnMatrix(int Cols)
{
Matrix ColMatrix(1,Cols);
@@ -265,7 +222,7 @@
}
-
+/// To Implicitly create a Single Row Matrix.
Matrix Matrix::CreateRowMatrix(int Rows)
{
Matrix RowMatrix( Rows, 1);
@@ -273,106 +230,187 @@
}
-
-void Matrix::Clone( const Matrix &Source, Matrix Receip )
+/// To implicitly Clone a Matrix. Although '=' works the same.
+void Matrix::Clone( const Matrix &Source, Matrix &Receip )
{
- Receip._Cols = Source._Cols;
- Receip._Rows = Source._Rows;
+ Receip._nCols = Source._nCols;
+ Receip._nRows = Source._nRows;
- Receip._matrix.resize(Receip._Rows);
- for( int i = 0; i < Receip._Rows; i++ )
- Receip._matrix[i].resize(Receip._Cols);
+ Receip._matrix.resize(Receip._nRows);
+ for( int i = 0; i < Receip._nRows; i++ )
+ Receip._matrix[i].resize(Receip._nCols);
- for( int i = 0; i < Receip._Rows; i++ )
- for( int j = 0; j < Receip._Cols; j++ )
+ for( int i = 0; i < Receip._nRows; i++ )
+ for( int j = 0; j < Receip._nCols; j++ )
Receip._matrix[i][j] = Source._matrix[i][j];
}
-void Matrix::DeleteRow(Matrix& Mat, int Row)
+/// To add (Insert) a Single Row to a Matrix.
+void Matrix::AddRow(Matrix& Mat, int Row)
{
--Row;
- if( Row > Mat._Rows )
+ if( Row > Mat._nRows + 1)
{
- printf("\nERROR:\nColumn out of Limits on DeleteCol()\n");
-
+ printf("\n\nERROR:\nRow out of Limits @ AddRow()\n");
+
}else{
- for( int i = Row; i < Mat._Rows - 1; i++ )
-
- for( int j = 0; j < Mat._Cols; j++ )
- Mat._matrix[i][j] = Mat._matrix[i+1][j];
- Mat._Rows--;
- Mat._matrix.resize(Mat._Rows);
+ Mat._nRows++;
+ Mat._matrix.resize( Mat._nRows );
+
+ Mat._matrix[ Mat._nRows - 1 ].resize( Mat._nCols );
+
+ for( int i = Mat._nRows - 1; i > Row; i-- )
+ for( int j = 0; j < Mat._nCols; j++ )
+ Mat._matrix[i][j] = Mat._matrix[i - 1][j];
+
+ for( int j = 0; j < Mat._nCols; j++ )
+ Mat._matrix[Row][j] = 0.0;
}
}
+/// To add (Insert) a single Column to a Matrix
+void Matrix::AddColumn( Matrix &Mat, int Col )
+{
+ --Col;
+ if( Col > Mat._nCols + 1 )
+ {
+ printf("\n\nERROR:\nRow out of Limits on AddCol()\n");
+
+ }else{
+
+
+ Mat._nCols++;
+ for( int i = 0; i < Mat._nRows; i++ )
+ Mat._matrix[i].resize( Mat._nCols );
+
+ for( int i = 0; i < Mat._nRows; i++ )
+ for( int j = Mat._nCols; j > Col; j-- )
+ Mat._matrix[i][j] = Mat._matrix[i][j - 1];
+
+ for( int i = 0; i < Mat._nRows; i++ )
+ Mat._matrix[i][Col] = 0.0;
+
+ }
+}
+
+
+/// Delete a Single Column From Matrix.
void Matrix::DeleteCol( Matrix &Mat, int Col)
{
--Col; // Because of Column zero.
- if( Col > Mat._Cols )
+ if( Col > Mat._nCols )
{
- printf("\nERROR:\nColumn out of Limits on DeleteCol()\n");
-
+ printf("\n\nERROR:\nColumn out of Limits @ DeleteCol()\n");
+
}else{
- for( int i = 0; i < Mat._Rows; i++ )
- for( int j = Col; j < Mat._Cols; j++ )
+ for( int i = 0; i < Mat._nRows; i++ )
+ for( int j = Col; j < Mat._nCols; j++ )
Mat._matrix[i][j] = Mat._matrix[i][j+1];
// Decrease one column
- Mat._Cols--;
+ Mat._nCols--;
//Erase last Column
- for( int i = 0; i < Mat._Rows; i++ )
- Mat._matrix[i].reserve(Mat._Cols);
+ for( int i = 0; i < Mat._nRows; i++ )
+ Mat._matrix[i].reserve(Mat._nCols);
}
}
-//---------------------------------------------------------------
+
+/// Delete a Single Row form Matrix
+void Matrix::DeleteRow(Matrix& Mat, int Row)
+{
+ --Row;
-//*** Methods returning nothing VOID ***//
+ if( Row > Mat._nRows )
+ {
+ printf("\n\nERROR:\nColumn out of Limits @ DeleteCol()\n");
+
+ }else{
-void Matrix::Add(int Row, int Col, float number)
+ for( int i = Row; i < Mat._nRows - 1; i++ )
+
+ for( int j = 0; j < Mat._nCols; j++ )
+ Mat._matrix[i][j] = Mat._matrix[i+1][j];
+ Mat._nRows--;
+ Mat._matrix.resize(Mat._nRows);
+ }
+}
+
+/*****************************************************************************************/
+
+/// Extracts a single row form calling matrix and saves it to another matrix.
+void Matrix::ExportRow( int Row, Matrix &Mat )
{
- if( Row > _Rows || Col > _Cols )
+ --Row;
+
+ if( Row > this->_nRows )
{
- printf("\nERROR:\n@ Matrix::Add, Out of limits of Matrix\n");
+ printf( "\n\nWARNING: Row out of dimmensions @ GetRow\n"
+ "Nothing Done.\n\n" );
}else{
- _matrix[Row][Col] = number;
+
+ Matrix SingleRow( 1 , this->_nCols );
+ SingleRow.Clear();
+
+ for( int j = 0; j < this->_nCols; j++ )
+ SingleRow._matrix[0][j] = this->_matrix[Row][j];
+
+ Mat = SingleRow;
}
-
-
-}
-
-void Matrix::Resize( int Rows, int Cols )
-{
- this->_Rows = Rows;
- this->_Cols = Cols;
- this->_matrix.resize( _Rows );
-
- for( int i = 0; i< _Rows ; i++ )
- _matrix[i].resize(_Cols);
}
+/// Extracts a single column form calling matrix and saves it to another matrix.
+void Matrix::ExportCol( int Col, Matrix &Mat )
+{
+ if( Col > this->_nCols )
+ {
+ printf( "\n\nWARNING:\nCol out of dimmensions.\n"
+ "Nothing Done.\n\n" );
+ }else{
+
+ Matrix SingleCol( this->_nRows, 1 );
+ for(int i = 0; i < this->_nRows; i++ )
+ SingleCol._matrix[i][0] = this->_matrix[i][Col];
+ Mat = SingleCol;
+ }
+}
+
+
+/// Makes matrix Bigger!
+void Matrix::Resize( int Rows, int Cols )
+{
+ this->_nRows = Rows;
+ this->_nCols = Cols;
+ this->_matrix.resize( _nRows );
+
+ for( int i = 0; i< _nRows ; i++ )
+ _matrix[i].resize(_nCols);
+}
+
+
+/// Ask user for elemnts in Matrix
void Matrix::FillMatrix()
{
- for(int i = 0; i < _Rows; i++)
+ for(int i = 0; i < _nRows; i++)
{
- for(int j = 0; j < _Cols; j++)
+ for(int j = 0; j < _nCols; j++)
{
printf( "Position [%u][%u]: ", i, j );
float numero;
scanf( "%f", &numero );
printf("%.3f ", numero);
- this->Add( i, j, numero);
+ this->_matrix[i][j] = numero;
}
printf("\n");
}
@@ -380,48 +418,65 @@
}
-void Matrix::Clear()
-{
- for( int i = 0; i < _Rows; i++ )
- for( int j = 0; j < _Cols; j++ )
- _matrix[i][j] = 0;
- }
-
+/// Prints out Matrix.
void Matrix::print()
{
- for( int i = 0; i < _Rows; i++ )
+ for( int i = 0; i < _nRows; i++ )
{
- for( int j = 0; j < _Cols; j++ )
+ for( int j = 0; j < _nCols; j++ )
{
printf( "%.3f, ",_matrix[i][j] );
+
}
- printf( "\n" );
+ printf( "\n" );
}
}
+/// Fills matrix with zeros.
+void Matrix::Clear()
+{
+ for( int i = 0; i < _nRows; i++ )
+ for( int j = 0; j < _nCols; j++ )
+ _matrix[i][j] = 0;
+}
-float Matrix::Sum()
+/********************************************************************************/
+
+/// Inserts a Single element in a desired Position( Index starts at [1][1] );
+void Matrix::add(int Row, int Col, float number)
+{
+ --Col; --Row;
+
+ if( Row > _nRows || Col > _nCols )
+ {
+ printf("\n\nERROR:\nOut of limits of Matrix @ mat.Add()");
+
+ }else{
+ _matrix[Row][Col] = number;
+ }
+}
+
+
+/// Adds all elements in matrix and returns the answer.
+float Matrix::sum()
{
float total;
- for( int i = 0; i < this->_Rows; i++ )
- for( int j = 0; j < this->_Cols; j++ )
+ for( int i = 0; i < this->_nRows; i++ )
+ for( int j = 0; j < this->_nCols; j++ )
total += this->_matrix[i][j];
return total;
}
+/// Returns the specified element. Index Starts at [1][1].
+float Matrix::getNumber( int Row, int Col )
+{ return this->_matrix[Row -1][Col - 1]; }
-float Matrix::GetNumber( int Row, int Col )
-{
- return this->_matrix[Row][Col];
-}
+/// Returns the number of Rows in Matrix.
+int Matrix::getRows(){ return this->_nRows; }
-int Matrix::getRows(){ return this->_Rows; }
-
-int Matrix::getCols(){ return this->_Cols; }
-
-
-
+/// Returns the number of Columns in Matrix.
+int Matrix::getCols(){ return this->_nCols; }
--- a/Matrix.h Fri Sep 23 21:12:17 2011 +0000
+++ b/Matrix.h Mon Sep 26 03:23:35 2011 +0000
@@ -9,10 +9,12 @@
*
*/
+#ifndef MATRIX_H
+#define MATRIX_H
+
#include <vector>
-#ifndef MATRIX_H
-#define MATRIX_H
+using namespace std;
/**
* @brief This class is intended to provide basic functionality to a Matrix like vector
@@ -32,7 +34,7 @@
* myMatrix.print(); // Re-prints Matrix
*
* Matrix anotherMatrix (3); // Squared 3x3 Matrix
- * anotherMatrix = myMatrix; // Re-Sizes 'anotherMatrix' to fit myMatrix
+ * anotherMatrix = myMatrix; // Re-Sizes 'anotherMatrix' to fit myMatrix and copies data.
* anotherMatrix += myMatrix; // Adds one-by-one elements and saves to anotherMatrix
* anotherMatrix.print();
* @endcode
@@ -44,7 +46,7 @@
/// Creates a nex Matrix of Size [ Row x Cols ]
Matrix( int Rows, int Cols );
- /// Creats a Square Matrix o Size [ Roxs x Rows ]
+ /// Creats a Square Matrix o Size [ Rows x Rows ]
Matrix( int Rows );
@@ -57,14 +59,15 @@
- /** @brief Description:
+ /** @brief
* This is the '=' Overloaded operator. It RESIZES assigned the matrix.
* Overwrites all data. To be used Carefully!
*/
Matrix& operator = ( const Matrix &rightM );
- /**@brief Description:
+
+ /** @brief
* Overload opeartor for the compare Matrices
*
* @param rightM
@@ -74,7 +77,7 @@
- /**@brief Description:
+ /** @brief
* Overload opeartor for the compare Matrices
*
* @param rightM
@@ -82,8 +85,9 @@
*/
bool operator != ( const Matrix &rightM );
- /**@brief
- * Description:
+
+
+ /** @brief
* Overload Copmpound assignment.
* @param rightM
* @return A new Matrix to be assigned to itself.
@@ -92,8 +96,7 @@
- /**@brief
- * Description:
+ /** @brief
* Overload Compund decrease.
* @param rightM Right hand matrix
* @return A new Matrix to be assigned to itself
@@ -102,58 +105,25 @@
- /**@brief
- * Description:
+ /** @brief
* Overloads the Plus, returns a new object.
* @param rightM right side Matrix
* @return Retuns an instance of the answer.
*/
const Matrix operator +( const Matrix &rightM );
+
- /**@brief
- * Description:
+ /** @brief
* Overloads the Minus, returns a new object
* @param rightM
* @return Returns an instance of the asnwer
*/
const Matrix operator -( const Matrix &rightM );
-
-
- /** @brief
- * Description:
- * This method extracts a Row from a Matrix.
- * If Row is out of the parameters, it returns
- * an empty Row and prints a warning
- * @param Matrix: Matrix to extract from
- * @param Row: row number of the matrix
- */
- Matrix GetRow(Matrix mat, int Row);
-
-
-
+
+
/** @brief
- * Description:
- * This method extracts a Column from a Matrix.
- * If Row is out of the parameters, it returns
- * an empty Column and prints a warning
- */
- Matrix GetCol(Matrix mat, int Col);
-
-
-
- /** @brief
- * Description:
- * Shatters the matrix into a single Row Vector.
- * Important: Returns NEW matrix, does no modify existing one.
- */
- Matrix ToPackedVector();
-
-
-
- /** @brief
- * Description:
* Returns TRUE if the matrix is zero, FALSE otherwhise
* @param mat: Matrix to be tested
*/
@@ -162,25 +132,30 @@
/** @brief
- * Description:
* Determines weather a Matrix is a Single Column or Row.
*/
bool isVector();
+
+ /** @brief
+ * Shatters the matrix into a single Row Vector.
+ * Important: Returns NEW matrix, does no modify existing one.
+ */
+ Matrix ToPackedVector();
- /**@brief
- * Description:
+
+
+ /** @brief
* Determines if two matrices are equal.
* @param mat1: First Matrix
* @param mat2: Sencond Matrix
*/
- static const bool Equals( Matrix mat1, Matrix mat2 );
+ static bool Equals( const Matrix mat1, const Matrix mat2 );
/**@brief
- * Description:
* This Funcrions instanciates a new Row Matrix. Since this is a
* static function it needs to be assigned to an Empy Matrix Object
* @param Rows: Number of Rows
@@ -189,9 +164,7 @@
-
- /**@brief
- * Description:
+ /** @brief
* This function instanciates a new Column Matrix. Since this is a
* static function it needs to be assigned to an Empty Matrix object
* @param Cols: Number of Columns in Matrix
@@ -200,8 +173,7 @@
- /**@brief
- * Description:
+ /** @brief
* This STATIC function Clones two Matrices.
* The Source Matrix can be any Size.
* The Receip Matrix MUST be just initialized
@@ -209,12 +181,30 @@
* @param Source: Base Matrix to Clone.
* @param Receip: Destination shell matrix
*/
- static void Clone( const Matrix &Source, Matrix Receip );
-
+ static void Clone( const Matrix &Source, Matrix &Receip );
+
+ /** @brief
+ * Invoking this static method will increase a Row in Mat in the desired
+ * position.
+ * The current Row will be moved down to allocate space, and all elements will
+ * be initialized to zero in the new row.
+ * @param Mat: Matrix in wich to insert a Row
+ * @param Row: Number of row to insert, starts with one, not zero.
+ */
+ static void AddRow( Matrix &Mat, int Row );
- /**@brief
- * Description:
+
+ /** @brief
+ * Invoking this static method will increase a Column in Matrix in the
+ * desired Position.
+ * @param Mat: Matrix in wich to insert a Column
+ * @param Col: Number of column, strats with one, not zero.
+ */
+ static void AddColumn( Matrix &Mat, int Col );
+
+
+ /** @brief
* Static Function Deletes Row from Matrix, Static to prevent missuse
* @param Mat: Matrix to delete Row from
* @param Row: Number of Row (first Row = 1)
@@ -222,32 +212,43 @@
static void DeleteRow( Matrix &Mat, int Row );
- /**@brief
- * Description:
+ /** @brief
* Static Function Deletes Column from Matrix, it's Static to prevent
* missuse.
* Print error and does nothing if out of limits.
- * @Mat: Matrix to delete column from
* @param Col: Number of Col to delete (first Col = 1)
+ * @param Mat: Matrix to delete from.
*/
static void DeleteCol( Matrix &Mat, int Col );
- /**@brief
- * Description:
- * Assigns a float number to the matrix in position
- *
- * @param number: Number to be set
- * @param Row: Row of Matrix
- * @param Col: Column of Matrix
+
+ /** @brief
+ * This method extracts a Row from a Matrix and Saves it in Mat.
+ * If Row is out of the parameters it does nothing, but prints a warning.
+ * @param Row: number of row to extract elements. this->_nRows.
+ * @param Mat: Matrix to resize if neccesaty and save data.
*/
- void Add( int Row, int Col, float number );
+ void ExportRow( int Row, Matrix &Mat);
+
+
+
+
+
+
+
+ /** @brief
+ * This method extracts a Column from a Matrix and saves it to Mat.
+ * If Row is out of the parameters, it does nothing and prints a warning.
+ * @param Col: number of Column to extract elements. this->_nCols.
+ * @param Mat: Matrix to save data to.
+ */
+ void ExportCol( int Col, Matrix &Mat );
- /**@brief
- * Description:
+ /** @brief
* This function resizes the Matrix to fit new data.
* @param Rows: New Number of Rows
* @param Cols: New numbler of columns
@@ -257,53 +258,64 @@
/** @brief
- * Description:
- * Asks user for numbers to fill the Matrix elements. One by one
+ * Asks user for numbers to fill the Matrix elements, one by one.
+ * It uses printf(); by default the USBTX, USBRX, 9600, 1N8.
*/
void FillMatrix();
/** @brief
- * Description:
- * Makes all values on Matrix object zero.
- */
- void Clear();
-
-
-
- /** @brief
- * Description:
* Prints the entire Matrix
*/
void print();
+
+ /** @brief
+ * Makes all values on Matrix object zero.
+ */
+ void Clear();
- /** \brief
- * Description:
- * Returns the sum of every cell in the Matrix.
+
+ /** @brief
+ * Assigns a float number to the matrix in a specified position
+ * Index starts at [1][1].
+ *
+ * @param number: Number to be set
+ * @param Row: Row of Matrix
+ * @param Col: Column of Matrix
*/
- float Sum();
+ void add( int Row, int Col, float number );
+
/** @brief
- * Description:
+ * Returns the sum of every cell in the Matrix.
+ */
+ float sum();
+
+
+ /** @brief
* Return the number in position [Row],[Col]
* @param Row = number of row in matrix
* @param Col = number of Col in matrix
* @return Num = float number in matrix
*/
- float GetNumber( int Row, int Col );
+ float getNumber( int Row, int Col );
- /**Retuns the number of Columns in Matrix*/
+ /**@brief
+ * Retuns the number of Columns in Matrix
+ */
int getCols();
- /**Retruns the number of Rows in Matrix */
+ /**@brief
+ *Retruns the number of Rows in Matrix
+ */
int getRows();
@@ -313,10 +325,10 @@
vector < vector<float> > _matrix;
/** Number of Rows in Matrix*/
- int _Rows;
+ int _nRows;
/**Number of Columns in Matrix*/
- int _Cols;
+ int _nCols;
};