Matrix Library. v1.6.4 + some changes
Diff: Matrix.h
- Revision:
- 4:c0c8f3edd60e
- Parent:
- 3:589fb80932b5
- Child:
- 5:a4014ab0a8cf
--- a/Matrix.h Fri Oct 21 03:33:53 2011 +0000 +++ b/Matrix.h Sat Oct 22 23:19:51 2011 +0000 @@ -1,9 +1,8 @@ - -/** +/** * @file Matrix.h * @author Ernesto Palacios * Created on 13 de septiembre de 2011, 03:49 PM - * + * * Develop Under GPL v3.0 License * http://www.gnu.org/licenses/gpl-3.0.html * @@ -19,12 +18,9 @@ using namespace std; /** - * @brief This class provide basic manipulation for 2D matrices. - * - * Intended to be ported to mbed.org - * - * v1.6 - * + * @brief This class provide basic manipulation for 2D matrices see Log.c for more info + * version 1.6.2. + * */ class Matrix{ public: @@ -49,13 +45,11 @@ friend class MatrixMath; - /** @brief * Overwrites all data. To be used Carefully! */ Matrix& operator = ( const Matrix& rightM ); - - + /** @brief * Overload opeartor for the compare Matrices @@ -66,7 +60,6 @@ bool operator == ( const Matrix& rightM ); - /** @brief * Overload opeartor for the compare Matrices * @@ -76,7 +69,6 @@ bool operator != ( const Matrix& rightM ); - /** @brief * Overload Copmpound assignment. * @param rightM @@ -85,7 +77,6 @@ Matrix& operator += ( const Matrix& rightM ); - /** @brief * Overload Compund decrease. * @param rightM Right hand matrix @@ -94,7 +85,6 @@ Matrix& operator -= ( const Matrix& rightM ); - /** @brief * Overload Compound CrossProduct Matrix operation. * @param rightM @@ -103,7 +93,6 @@ Matrix& operator *=( const Matrix& rightM ); - /** @brief * Overload Compund Element-by-elemnt scalar multiplication. * @param number @@ -120,7 +109,6 @@ const Matrix operator -(); - /**@brief * Overload Compound add with scalar. * Because the '=' operator checks for self Assign, no extra operations @@ -130,7 +118,6 @@ friend const Matrix operator +=( Matrix& leftM, float number ); - /**@brief * Compound substract with scalar. * @return Same matrix to self Assign. @@ -138,7 +125,6 @@ friend const Matrix operator -=( Matrix& leftM, float number ); - /** @brief * Adds two matrices of the same dimensions, element-by-element. * If diferent dimensions -> ERROR. @@ -147,7 +133,6 @@ friend const Matrix operator +( const Matrix& leftM, const Matrix& rightM); - /** @brief * Adds the given nomber to each element of matrix. * Mimic MATLAB operation. @@ -164,7 +149,6 @@ friend const Matrix operator +( float number, const Matrix& leftM ); - /**@brief * Substracts two matrices of the same size, element-by-element. * If different dimensions -> ERROR. @@ -173,7 +157,6 @@ friend const Matrix operator -( const Matrix& leftM, const Matrix& rightM ); - /**@brief * Substracts each element in Matrix by number. * @return A new matrix object with the result. @@ -181,7 +164,6 @@ friend const Matrix operator -( const Matrix& leftM, float number ); - /**@brief * Substracts each element in Matrix by number * @return A new matrix object with the result. @@ -189,15 +171,13 @@ friend const Matrix operator -( float number, const Matrix& leftM ); - /** * Preforms Crossproduct between two matrices. - * @return + * @return */ friend const Matrix operator *( const Matrix& leftM, const Matrix& rightM ); - /**@brief * Multiplies a scalar number with each element on Matrix. * @return A new object with the result. @@ -205,7 +185,6 @@ friend const Matrix operator *( const Matrix& leftM, float number ); - /**@brief * Multiplies a scalar number with each element on Matrix. * @return @@ -213,7 +192,6 @@ friend const Matrix operator *( float number, const Matrix& leftM ); - /**@brief * Inputs numbres into a Matrix, the matrix needs to be costructed as * Matrix( _nRows, _nCols ). @@ -233,14 +211,12 @@ bool isZero(); - /** @brief * 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. @@ -248,7 +224,6 @@ static const Matrix ToPackedVector( const Matrix& Mat ); - /** @brief * Invoking this static method will increase a Row in Mat in the desired * position. @@ -257,7 +232,19 @@ * @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 ); + static void AddRow( Matrix& Mat, int index ); + + + /**@brief + * Adds to Receip a new Row from another Matrix in desired index. + * Must be same size. + * The Row matrix must be SingleRow Matrix, you can use ExportRow + * to extract a Row from another Matrix. + * @param Receip Matrix to be Modified. + * @param Row Row to be added. + * @param index position in wich to be added, _nRow + 1 last position. + */ + static void AddRow( Matrix& Receip, const Matrix& Row, int index ); /** @brief @@ -266,7 +253,19 @@ * @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 ); + static void AddCol( Matrix& Mat, int index ); + + + /**@brief + * This will copy a Column Matrix into Receip in desired Position, + * Must be same size. + * The Col Matrix must be a SingleCol Matrix, you can use ExportCol + * to extract a Column from another Matrix. + * @param Receip Matrix to be modified. + * @param Column Data to be copied. + * @param index Postion in Receip Matrix . + */ + static void AddCol( Matrix& Receip, const Matrix& Col, int index ); /** @brief @@ -287,8 +286,6 @@ static void DeleteCol( Matrix& Mat, int Col ); - - /** @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. @@ -299,7 +296,6 @@ static const Matrix ExportRow( const Matrix& Mat, int row ); - /** @brief * This method extracts a Column from a Matrix and returns the Column * as a new Matrix. @@ -311,11 +307,9 @@ static const Matrix ExportCol( const Matrix& Mat, int col ); - /** @brief * This function resizes the Matrix to fit new data or cropped it, - * to use newly created memory use .add() not << operator. - * << operator overwites everithing + * operator << can overwrite entire Matrix. * * @param Rows: New Number of Rows * @param Cols: New numbler of columns @@ -323,7 +317,6 @@ void Resize( int Rows, int Cols ); - /** @brief * Asks user for numbers to fill the Matrix elements, one by one. * It uses printf(); by default the USBTX, USBRX, 9600, 1N8. @@ -331,14 +324,12 @@ virtual void FillMatrix(); - /** @brief * Prints the entire Matrix using standard PRINTF */ virtual void print(); - /** @brief * Makes all values on Matrix object zero. * Also make posible use the '<<' operator to add elements and keep @@ -358,7 +349,6 @@ void add( int Row, int Col, float number ); - /** @brief * Returns the sum of every cell in the Matrix. */ @@ -374,14 +364,12 @@ float getNumber( int Row, int Col ); - /**@brief * Retuns the number of Columns in Matrix, index starts at 1. */ int getCols(); - /**@brief *Retruns the number of Rows in Matrix, index starts at 1. */ @@ -394,7 +382,7 @@ vector < vector<float> > _matrix; - + /** Number of Rows in Matrix*/ int _nRows; @@ -413,3 +401,10 @@ #endif /* MATRIX_H */ +/* + * Things To Change -> Enhace -> Modify + * + * Submatrix + // .submat(first_row, first_column, last_row, last_column) + * + */