Niet af

Fork of Matrix by Ernesto Palacios

Committer:
Yo_Robot
Date:
Thu Oct 20 23:42:13 2011 +0000
Revision:
2:493402568a5e
Parent:
1:48f417da268e
Child:
3:589fb80932b5
Everything working fine, dropped some useless methods, Matrix Class is Complete, maybe I\ll keep adding stuff but basic usage is covered in my opinion.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yo_Robot 0:3abd8c2d7c34 1
Yo_Robot 0:3abd8c2d7c34 2 /**
Yo_Robot 0:3abd8c2d7c34 3 * @file: Matrix.h
Yo_Robot 0:3abd8c2d7c34 4 * @author: Ernesto Palacios
Yo_Robot 0:3abd8c2d7c34 5 * Created on 13 de septiembre de 2011, 03:49 PM
Yo_Robot 0:3abd8c2d7c34 6 *
Yo_Robot 0:3abd8c2d7c34 7 * Develop Under GPL v3.0 License
Yo_Robot 0:3abd8c2d7c34 8 * http://www.gnu.org/licenses/gpl-3.0.html
Yo_Robot 0:3abd8c2d7c34 9 *
Yo_Robot 0:3abd8c2d7c34 10 */
Yo_Robot 0:3abd8c2d7c34 11
Yo_Robot 1:48f417da268e 12 #ifndef MATRIX_H
Yo_Robot 2:493402568a5e 13 #define MATRIX_H
Yo_Robot 2:493402568a5e 14
Yo_Robot 1:48f417da268e 15
Yo_Robot 0:3abd8c2d7c34 16 #include <vector>
Yo_Robot 0:3abd8c2d7c34 17
Yo_Robot 2:493402568a5e 18 class MatrixMath;
Yo_Robot 2:493402568a5e 19
Yo_Robot 1:48f417da268e 20 using namespace std;
Yo_Robot 0:3abd8c2d7c34 21 /**
Yo_Robot 2:493402568a5e 22 * @brief This class provide basic manipulation for 2D matrices.
Yo_Robot 0:3abd8c2d7c34 23 *
Yo_Robot 2:493402568a5e 24 * Intended to be ported to mbed.org
Yo_Robot 0:3abd8c2d7c34 25 *
Yo_Robot 2:493402568a5e 26 * v1.01
Yo_Robot 2:493402568a5e 27 *
Yo_Robot 0:3abd8c2d7c34 28 */
Yo_Robot 0:3abd8c2d7c34 29 class Matrix{
Yo_Robot 0:3abd8c2d7c34 30 public:
Yo_Robot 0:3abd8c2d7c34 31
Yo_Robot 0:3abd8c2d7c34 32 /// Creates a nex Matrix of Size [ Row x Cols ]
Yo_Robot 0:3abd8c2d7c34 33 Matrix( int Rows, int Cols );
Yo_Robot 0:3abd8c2d7c34 34
Yo_Robot 0:3abd8c2d7c34 35
Yo_Robot 2:493402568a5e 36 /// Creates a new Matrix identical to an input Matrix
Yo_Robot 2:493402568a5e 37 Matrix( const Matrix& base );
Yo_Robot 0:3abd8c2d7c34 38
Yo_Robot 0:3abd8c2d7c34 39
Yo_Robot 0:3abd8c2d7c34 40 /// Reserves Memory for a New Matrix
Yo_Robot 0:3abd8c2d7c34 41 Matrix();
Yo_Robot 0:3abd8c2d7c34 42
Yo_Robot 0:3abd8c2d7c34 43
Yo_Robot 2:493402568a5e 44 /******************************************************************************/
Yo_Robot 0:3abd8c2d7c34 45
Yo_Robot 1:48f417da268e 46 /** @brief
Yo_Robot 0:3abd8c2d7c34 47 * This is the '=' Overloaded operator. It RESIZES assigned the matrix.
Yo_Robot 0:3abd8c2d7c34 48 * Overwrites all data. To be used Carefully!
Yo_Robot 0:3abd8c2d7c34 49 */
Yo_Robot 2:493402568a5e 50 Matrix& operator = ( const Matrix& rightM );
Yo_Robot 2:493402568a5e 51
Yo_Robot 2:493402568a5e 52
Yo_Robot 2:493402568a5e 53
Yo_Robot 2:493402568a5e 54 /**@brief This includes the Class to handle Matrix Operations.
Yo_Robot 2:493402568a5e 55 */
Yo_Robot 2:493402568a5e 56 friend class MatrixMath;
Yo_Robot 0:3abd8c2d7c34 57
Yo_Robot 0:3abd8c2d7c34 58
Yo_Robot 2:493402568a5e 59
Yo_Robot 1:48f417da268e 60 /** @brief
Yo_Robot 0:3abd8c2d7c34 61 * Overload opeartor for the compare Matrices
Yo_Robot 0:3abd8c2d7c34 62 *
Yo_Robot 0:3abd8c2d7c34 63 * @param rightM
Yo_Robot 0:3abd8c2d7c34 64 * @return Boolean 'false' if different.
Yo_Robot 0:3abd8c2d7c34 65 */
Yo_Robot 2:493402568a5e 66 bool operator == ( const Matrix& rightM );
Yo_Robot 0:3abd8c2d7c34 67
Yo_Robot 0:3abd8c2d7c34 68
Yo_Robot 0:3abd8c2d7c34 69
Yo_Robot 1:48f417da268e 70 /** @brief
Yo_Robot 0:3abd8c2d7c34 71 * Overload opeartor for the compare Matrices
Yo_Robot 0:3abd8c2d7c34 72 *
Yo_Robot 0:3abd8c2d7c34 73 * @param rightM
Yo_Robot 0:3abd8c2d7c34 74 * @return Boolean 'true' if different
Yo_Robot 0:3abd8c2d7c34 75 */
Yo_Robot 2:493402568a5e 76 bool operator != ( const Matrix& rightM );
Yo_Robot 0:3abd8c2d7c34 77
Yo_Robot 2:493402568a5e 78
Yo_Robot 2:493402568a5e 79
Yo_Robot 1:48f417da268e 80 /** @brief
Yo_Robot 0:3abd8c2d7c34 81 * Overload Copmpound assignment.
Yo_Robot 0:3abd8c2d7c34 82 * @param rightM
Yo_Robot 0:3abd8c2d7c34 83 * @return A new Matrix to be assigned to itself.
Yo_Robot 0:3abd8c2d7c34 84 */
Yo_Robot 2:493402568a5e 85 Matrix& operator += ( const Matrix& rightM );
Yo_Robot 0:3abd8c2d7c34 86
Yo_Robot 0:3abd8c2d7c34 87
Yo_Robot 0:3abd8c2d7c34 88
Yo_Robot 1:48f417da268e 89 /** @brief
Yo_Robot 0:3abd8c2d7c34 90 * Overload Compund decrease.
Yo_Robot 0:3abd8c2d7c34 91 * @param rightM Right hand matrix
Yo_Robot 0:3abd8c2d7c34 92 * @return A new Matrix to be assigned to itself
Yo_Robot 0:3abd8c2d7c34 93 */
Yo_Robot 2:493402568a5e 94 Matrix& operator -= ( const Matrix& rightM );
Yo_Robot 2:493402568a5e 95
Yo_Robot 2:493402568a5e 96
Yo_Robot 2:493402568a5e 97
Yo_Robot 2:493402568a5e 98 /** @brief
Yo_Robot 2:493402568a5e 99 * Overload Compound CrossProduct Matrix operation.
Yo_Robot 2:493402568a5e 100 * @param rightM
Yo_Robot 2:493402568a5e 101 * @return
Yo_Robot 2:493402568a5e 102 */
Yo_Robot 2:493402568a5e 103 Matrix& operator *=( const Matrix& rightM );
Yo_Robot 2:493402568a5e 104
Yo_Robot 2:493402568a5e 105
Yo_Robot 2:493402568a5e 106
Yo_Robot 2:493402568a5e 107 /** @brief
Yo_Robot 2:493402568a5e 108 * Overload Compund Element-by-elemnt scalar multiplication.
Yo_Robot 2:493402568a5e 109 * @param number
Yo_Robot 2:493402568a5e 110 * @return
Yo_Robot 2:493402568a5e 111 */
Yo_Robot 2:493402568a5e 112 Matrix& operator *=( float number );
Yo_Robot 2:493402568a5e 113
Yo_Robot 2:493402568a5e 114
Yo_Robot 2:493402568a5e 115
Yo_Robot 2:493402568a5e 116 /**@brief
Yo_Robot 2:493402568a5e 117 * Makes all elements in matrix negative.
Yo_Robot 2:493402568a5e 118 * Unary operator
Yo_Robot 2:493402568a5e 119 * @return A new Matrix object with inverted values.
Yo_Robot 2:493402568a5e 120 */
Yo_Robot 2:493402568a5e 121 const Matrix operator -();
Yo_Robot 2:493402568a5e 122
Yo_Robot 2:493402568a5e 123
Yo_Robot 2:493402568a5e 124
Yo_Robot 2:493402568a5e 125 /**@brief
Yo_Robot 2:493402568a5e 126 * Overload Compound add with scalar.
Yo_Robot 2:493402568a5e 127 * Because the '=' operator checks for self Assign, no extra operations
Yo_Robot 2:493402568a5e 128 * are needed.
Yo_Robot 2:493402568a5e 129 * @return Same Matrix to self Assign.
Yo_Robot 2:493402568a5e 130 */
Yo_Robot 2:493402568a5e 131 friend const Matrix operator +=( Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 132
Yo_Robot 2:493402568a5e 133
Yo_Robot 2:493402568a5e 134
Yo_Robot 2:493402568a5e 135 /**@brief
Yo_Robot 2:493402568a5e 136 * Compound substract with scalar.
Yo_Robot 2:493402568a5e 137 * @return Same matrix to self Assign.
Yo_Robot 2:493402568a5e 138 */
Yo_Robot 2:493402568a5e 139 friend const Matrix operator -=( Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 140
Yo_Robot 2:493402568a5e 141
Yo_Robot 2:493402568a5e 142
Yo_Robot 2:493402568a5e 143 /** @brief
Yo_Robot 2:493402568a5e 144 * Adds two matrices of the same dimensions, element-by-element.
Yo_Robot 2:493402568a5e 145 * If diferent dimensions -> ERROR.
Yo_Robot 2:493402568a5e 146 * @return A new object Matrix with the result.
Yo_Robot 2:493402568a5e 147 */
Yo_Robot 2:493402568a5e 148 friend const Matrix operator +( const Matrix& leftM, const Matrix& rightM);
Yo_Robot 0:3abd8c2d7c34 149
Yo_Robot 0:3abd8c2d7c34 150
Yo_Robot 0:3abd8c2d7c34 151
Yo_Robot 1:48f417da268e 152 /** @brief
Yo_Robot 2:493402568a5e 153 * Adds the given nomber to each element of matrix.
Yo_Robot 2:493402568a5e 154 * Mimic MATLAB operation.
Yo_Robot 2:493402568a5e 155 * @return A new matrix object with the result.
Yo_Robot 2:493402568a5e 156 */
Yo_Robot 2:493402568a5e 157 friend const Matrix operator +( const Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 158
Yo_Robot 2:493402568a5e 159
Yo_Robot 2:493402568a5e 160
Yo_Robot 2:493402568a5e 161 /**@brief
Yo_Robot 2:493402568a5e 162 * Adds the given number to each element in Matrix.
Yo_Robot 2:493402568a5e 163 * @return A new Matrix object with the result.
Yo_Robot 2:493402568a5e 164 */
Yo_Robot 2:493402568a5e 165 friend const Matrix operator +( float number, const Matrix& leftM );
Yo_Robot 2:493402568a5e 166
Yo_Robot 2:493402568a5e 167
Yo_Robot 2:493402568a5e 168
Yo_Robot 2:493402568a5e 169 /**@brief
Yo_Robot 2:493402568a5e 170 * Substracts two matrices of the same size, element-by-element.
Yo_Robot 2:493402568a5e 171 * If different dimensions -> ERROR.
Yo_Robot 2:493402568a5e 172 * @return A new object Matrix with the result.
Yo_Robot 2:493402568a5e 173 */
Yo_Robot 2:493402568a5e 174 friend const Matrix operator -( const Matrix& leftM, const Matrix& rightM );
Yo_Robot 2:493402568a5e 175
Yo_Robot 2:493402568a5e 176
Yo_Robot 2:493402568a5e 177
Yo_Robot 2:493402568a5e 178 /**@brief
Yo_Robot 2:493402568a5e 179 * Substracts each element in Matrix by number.
Yo_Robot 2:493402568a5e 180 * @return A new matrix object with the result.
Yo_Robot 0:3abd8c2d7c34 181 */
Yo_Robot 2:493402568a5e 182 friend const Matrix operator -( const Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 183
Yo_Robot 2:493402568a5e 184
Yo_Robot 2:493402568a5e 185
Yo_Robot 2:493402568a5e 186 /**@brief
Yo_Robot 2:493402568a5e 187 * Substracts each element in Matrix by number
Yo_Robot 2:493402568a5e 188 * @return A new matrix object with the result.
Yo_Robot 2:493402568a5e 189 */
Yo_Robot 2:493402568a5e 190 friend const Matrix operator -( float number, const Matrix& leftM );
Yo_Robot 2:493402568a5e 191
Yo_Robot 2:493402568a5e 192
Yo_Robot 2:493402568a5e 193
Yo_Robot 2:493402568a5e 194 /**
Yo_Robot 2:493402568a5e 195 * Preforms Crossproduct between two matrices.
Yo_Robot 2:493402568a5e 196 * @return
Yo_Robot 2:493402568a5e 197 */
Yo_Robot 2:493402568a5e 198 friend const Matrix operator *( const Matrix& leftM, const Matrix& rightM );
Yo_Robot 2:493402568a5e 199
Yo_Robot 2:493402568a5e 200
Yo_Robot 2:493402568a5e 201
Yo_Robot 2:493402568a5e 202 /**@brief
Yo_Robot 2:493402568a5e 203 * Multiplies a scalar number with each element on Matrix.
Yo_Robot 2:493402568a5e 204 * @return A new object with the result.
Yo_Robot 2:493402568a5e 205 */
Yo_Robot 2:493402568a5e 206 friend const Matrix operator *( const Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 207
Yo_Robot 2:493402568a5e 208
Yo_Robot 2:493402568a5e 209
Yo_Robot 2:493402568a5e 210 /**@brief
Yo_Robot 2:493402568a5e 211 * Multiplies a scalar number with each element on Matrix.
Yo_Robot 2:493402568a5e 212 * @return
Yo_Robot 2:493402568a5e 213 */
Yo_Robot 2:493402568a5e 214 friend const Matrix operator *( float number, const Matrix& leftM );
Yo_Robot 2:493402568a5e 215
Yo_Robot 0:3abd8c2d7c34 216
Yo_Robot 1:48f417da268e 217
Yo_Robot 2:493402568a5e 218 /**@brief
Yo_Robot 2:493402568a5e 219 * Inputs numbres into a Matrix, the matrix needs to be costructed as
Yo_Robot 2:493402568a5e 220 * Matrix( _nRows, _nCols ).
Yo_Robot 2:493402568a5e 221 * This does NOT work on an only declared Matrix such as:
Yo_Robot 2:493402568a5e 222 * Matrix obj;
Yo_Robot 2:493402568a5e 223 * obj << 5; //Error
Yo_Robot 2:493402568a5e 224 * @return
Yo_Robot 2:493402568a5e 225 */
Yo_Robot 2:493402568a5e 226 friend Matrix& operator <<( Matrix& leftM, float number );
Yo_Robot 0:3abd8c2d7c34 227
Yo_Robot 2:493402568a5e 228 /***********************************************************************/
Yo_Robot 0:3abd8c2d7c34 229
Yo_Robot 0:3abd8c2d7c34 230 /** @brief
Yo_Robot 0:3abd8c2d7c34 231 * Returns TRUE if the matrix is zero, FALSE otherwhise
Yo_Robot 0:3abd8c2d7c34 232 * @param mat: Matrix to be tested
Yo_Robot 0:3abd8c2d7c34 233 */
Yo_Robot 0:3abd8c2d7c34 234 bool isZero();
Yo_Robot 0:3abd8c2d7c34 235
Yo_Robot 0:3abd8c2d7c34 236
Yo_Robot 0:3abd8c2d7c34 237
Yo_Robot 0:3abd8c2d7c34 238 /** @brief
Yo_Robot 0:3abd8c2d7c34 239 * Determines weather a Matrix is a Single Column or Row.
Yo_Robot 0:3abd8c2d7c34 240 */
Yo_Robot 0:3abd8c2d7c34 241 bool isVector();
Yo_Robot 0:3abd8c2d7c34 242
Yo_Robot 0:3abd8c2d7c34 243
Yo_Robot 2:493402568a5e 244
Yo_Robot 1:48f417da268e 245 /** @brief
Yo_Robot 1:48f417da268e 246 * Shatters the matrix into a single Row Vector.
Yo_Robot 1:48f417da268e 247 * Important: Returns NEW matrix, does no modify existing one.
Yo_Robot 1:48f417da268e 248 */
Yo_Robot 2:493402568a5e 249 static const Matrix ToPackedVector( const Matrix& Mat );
Yo_Robot 0:3abd8c2d7c34 250
Yo_Robot 1:48f417da268e 251
Yo_Robot 2:493402568a5e 252
Yo_Robot 1:48f417da268e 253 /** @brief
Yo_Robot 0:3abd8c2d7c34 254 * Determines if two matrices are equal.
Yo_Robot 0:3abd8c2d7c34 255 * @param mat1: First Matrix
Yo_Robot 0:3abd8c2d7c34 256 * @param mat2: Sencond Matrix
Yo_Robot 0:3abd8c2d7c34 257 */
Yo_Robot 2:493402568a5e 258 static bool Equals( const Matrix& mat1, const Matrix& mat2 );
Yo_Robot 0:3abd8c2d7c34 259
Yo_Robot 0:3abd8c2d7c34 260
Yo_Robot 0:3abd8c2d7c34 261
Yo_Robot 1:48f417da268e 262 /** @brief
Yo_Robot 2:493402568a5e 263 * Invoking this static method will increase a Row in Mat in the desired
Yo_Robot 1:48f417da268e 264 * position.
Yo_Robot 1:48f417da268e 265 * The current Row will be moved down to allocate space, and all elements will
Yo_Robot 1:48f417da268e 266 * be initialized to zero in the new row.
Yo_Robot 2:493402568a5e 267 * @param Mat: Matrix in wich to insert a Row
Yo_Robot 1:48f417da268e 268 * @param Row: Number of row to insert, starts with one, not zero.
Yo_Robot 2:493402568a5e 269 */
Yo_Robot 2:493402568a5e 270 static void AddRow( Matrix& Mat, int Row );
Yo_Robot 0:3abd8c2d7c34 271
Yo_Robot 2:493402568a5e 272
Yo_Robot 1:48f417da268e 273 /** @brief
Yo_Robot 2:493402568a5e 274 * Invoking this static method will increase a Column in Matrix in the
Yo_Robot 1:48f417da268e 275 * desired Position.
Yo_Robot 1:48f417da268e 276 * @param Mat: Matrix in wich to insert a Column
Yo_Robot 1:48f417da268e 277 * @param Col: Number of column, strats with one, not zero.
Yo_Robot 1:48f417da268e 278 */
Yo_Robot 2:493402568a5e 279 static void AddColumn( Matrix& Mat, int Col );
Yo_Robot 2:493402568a5e 280
Yo_Robot 1:48f417da268e 281
Yo_Robot 1:48f417da268e 282 /** @brief
Yo_Robot 0:3abd8c2d7c34 283 * Static Function Deletes Row from Matrix, Static to prevent missuse
Yo_Robot 0:3abd8c2d7c34 284 * @param Mat: Matrix to delete Row from
Yo_Robot 0:3abd8c2d7c34 285 * @param Row: Number of Row (first Row = 1)
Yo_Robot 0:3abd8c2d7c34 286 */
Yo_Robot 2:493402568a5e 287 static void DeleteRow( Matrix& Mat, int Row );
Yo_Robot 0:3abd8c2d7c34 288
Yo_Robot 0:3abd8c2d7c34 289
Yo_Robot 1:48f417da268e 290 /** @brief
Yo_Robot 0:3abd8c2d7c34 291 * Static Function Deletes Column from Matrix, it's Static to prevent
Yo_Robot 0:3abd8c2d7c34 292 * missuse.
Yo_Robot 0:3abd8c2d7c34 293 * Print error and does nothing if out of limits.
Yo_Robot 0:3abd8c2d7c34 294 * @param Col: Number of Col to delete (first Col = 1)
Yo_Robot 1:48f417da268e 295 * @param Mat: Matrix to delete from.
Yo_Robot 0:3abd8c2d7c34 296 */
Yo_Robot 2:493402568a5e 297 static void DeleteCol( Matrix& Mat, int Col );
Yo_Robot 0:3abd8c2d7c34 298
Yo_Robot 0:3abd8c2d7c34 299
Yo_Robot 0:3abd8c2d7c34 300
Yo_Robot 1:48f417da268e 301
Yo_Robot 1:48f417da268e 302 /** @brief
Yo_Robot 1:48f417da268e 303 * This method extracts a Row from a Matrix and Saves it in Mat.
Yo_Robot 1:48f417da268e 304 * If Row is out of the parameters it does nothing, but prints a warning.
Yo_Robot 1:48f417da268e 305 * @param Row: number of row to extract elements. this->_nRows.
Yo_Robot 2:493402568a5e 306 * @param Mat: Matrix to extract from.
Yo_Robot 2:493402568a5e 307 * @return New Row Matrix.
Yo_Robot 0:3abd8c2d7c34 308 */
Yo_Robot 2:493402568a5e 309 static const Matrix ExportRow( const Matrix& Mat, int row );
Yo_Robot 0:3abd8c2d7c34 310
Yo_Robot 0:3abd8c2d7c34 311
Yo_Robot 0:3abd8c2d7c34 312
Yo_Robot 1:48f417da268e 313 /** @brief
Yo_Robot 2:493402568a5e 314 * This method extracts a Column from a Matrix and returns the Column
Yo_Robot 2:493402568a5e 315 * as a new Matrix.
Yo_Robot 2:493402568a5e 316 * If Row is out of the parameters, it does nothing and prints a warning.
Yo_Robot 2:493402568a5e 317 * @param Col: number of Column to extract elements. this->_nCols.
Yo_Robot 2:493402568a5e 318 * @param Mat: Matrix to extract from.
Yo_Robot 2:493402568a5e 319 * @return New Row Matrix.
Yo_Robot 2:493402568a5e 320 */
Yo_Robot 2:493402568a5e 321 static const Matrix ExportCol( const Matrix& Mat, int col );
Yo_Robot 2:493402568a5e 322
Yo_Robot 2:493402568a5e 323
Yo_Robot 2:493402568a5e 324
Yo_Robot 2:493402568a5e 325 /** @brief
Yo_Robot 2:493402568a5e 326 * This function resizes the Matrix to fit new data or cropped it,
Yo_Robot 2:493402568a5e 327 * to use newly created memory use .add() not << operator.
Yo_Robot 2:493402568a5e 328 * << operator overwites everithing
Yo_Robot 2:493402568a5e 329 *
Yo_Robot 0:3abd8c2d7c34 330 * @param Rows: New Number of Rows
Yo_Robot 0:3abd8c2d7c34 331 * @param Cols: New numbler of columns
Yo_Robot 0:3abd8c2d7c34 332 */
Yo_Robot 0:3abd8c2d7c34 333 void Resize( int Rows, int Cols );
Yo_Robot 0:3abd8c2d7c34 334
Yo_Robot 0:3abd8c2d7c34 335
Yo_Robot 0:3abd8c2d7c34 336
Yo_Robot 0:3abd8c2d7c34 337 /** @brief
Yo_Robot 1:48f417da268e 338 * Asks user for numbers to fill the Matrix elements, one by one.
Yo_Robot 1:48f417da268e 339 * It uses printf(); by default the USBTX, USBRX, 9600, 1N8.
Yo_Robot 0:3abd8c2d7c34 340 */
Yo_Robot 2:493402568a5e 341 virtual void FillMatrix();
Yo_Robot 0:3abd8c2d7c34 342
Yo_Robot 0:3abd8c2d7c34 343
Yo_Robot 0:3abd8c2d7c34 344
Yo_Robot 0:3abd8c2d7c34 345 /** @brief
Yo_Robot 2:493402568a5e 346 * Prints the entire Matrix using standard PRINTF
Yo_Robot 0:3abd8c2d7c34 347 */
Yo_Robot 2:493402568a5e 348 virtual void print();
Yo_Robot 0:3abd8c2d7c34 349
Yo_Robot 0:3abd8c2d7c34 350
Yo_Robot 2:493402568a5e 351
Yo_Robot 1:48f417da268e 352 /** @brief
Yo_Robot 1:48f417da268e 353 * Makes all values on Matrix object zero.
Yo_Robot 2:493402568a5e 354 * Also make posible use the '<<' operator to add elements and keep
Yo_Robot 2:493402568a5e 355 * track of last element added.
Yo_Robot 1:48f417da268e 356 */
Yo_Robot 1:48f417da268e 357 void Clear();
Yo_Robot 0:3abd8c2d7c34 358
Yo_Robot 2:493402568a5e 359
Yo_Robot 1:48f417da268e 360 /** @brief
Yo_Robot 1:48f417da268e 361 * Assigns a float number to the matrix in a specified position
Yo_Robot 1:48f417da268e 362 * Index starts at [1][1].
Yo_Robot 1:48f417da268e 363 *
Yo_Robot 1:48f417da268e 364 * @param number: Number to be set
Yo_Robot 1:48f417da268e 365 * @param Row: Row of Matrix
Yo_Robot 1:48f417da268e 366 * @param Col: Column of Matrix
Yo_Robot 0:3abd8c2d7c34 367 */
Yo_Robot 1:48f417da268e 368 void add( int Row, int Col, float number );
Yo_Robot 1:48f417da268e 369
Yo_Robot 0:3abd8c2d7c34 370
Yo_Robot 0:3abd8c2d7c34 371
Yo_Robot 0:3abd8c2d7c34 372 /** @brief
Yo_Robot 1:48f417da268e 373 * Returns the sum of every cell in the Matrix.
Yo_Robot 1:48f417da268e 374 */
Yo_Robot 1:48f417da268e 375 float sum();
Yo_Robot 1:48f417da268e 376
Yo_Robot 1:48f417da268e 377
Yo_Robot 1:48f417da268e 378 /** @brief
Yo_Robot 0:3abd8c2d7c34 379 * Return the number in position [Row],[Col]
Yo_Robot 0:3abd8c2d7c34 380 * @param Row = number of row in matrix
Yo_Robot 0:3abd8c2d7c34 381 * @param Col = number of Col in matrix
Yo_Robot 0:3abd8c2d7c34 382 * @return Num = float number in matrix
Yo_Robot 0:3abd8c2d7c34 383 */
Yo_Robot 1:48f417da268e 384 float getNumber( int Row, int Col );
Yo_Robot 0:3abd8c2d7c34 385
Yo_Robot 0:3abd8c2d7c34 386
Yo_Robot 2:493402568a5e 387
Yo_Robot 1:48f417da268e 388 /**@brief
Yo_Robot 2:493402568a5e 389 * Retuns the number of Columns in Matrix, index starts at 1.
Yo_Robot 1:48f417da268e 390 */
Yo_Robot 0:3abd8c2d7c34 391 int getCols();
Yo_Robot 0:3abd8c2d7c34 392
Yo_Robot 0:3abd8c2d7c34 393
Yo_Robot 0:3abd8c2d7c34 394
Yo_Robot 1:48f417da268e 395 /**@brief
Yo_Robot 2:493402568a5e 396 *Retruns the number of Rows in Matrix, index starts at 1.
Yo_Robot 1:48f417da268e 397 */
Yo_Robot 0:3abd8c2d7c34 398 int getRows();
Yo_Robot 0:3abd8c2d7c34 399
Yo_Robot 0:3abd8c2d7c34 400
Yo_Robot 0:3abd8c2d7c34 401 private:
Yo_Robot 0:3abd8c2d7c34 402
Yo_Robot 0:3abd8c2d7c34 403 /** 2-D Vector Array*/
Yo_Robot 0:3abd8c2d7c34 404 vector < vector<float> > _matrix;
Yo_Robot 0:3abd8c2d7c34 405
Yo_Robot 2:493402568a5e 406
Yo_Robot 2:493402568a5e 407
Yo_Robot 0:3abd8c2d7c34 408 /** Number of Rows in Matrix*/
Yo_Robot 1:48f417da268e 409 int _nRows;
Yo_Robot 0:3abd8c2d7c34 410
Yo_Robot 0:3abd8c2d7c34 411 /**Number of Columns in Matrix*/
Yo_Robot 1:48f417da268e 412 int _nCols;
Yo_Robot 0:3abd8c2d7c34 413
Yo_Robot 2:493402568a5e 414
Yo_Robot 2:493402568a5e 415
Yo_Robot 2:493402568a5e 416 /**Last Element Row position in Matrix*/
Yo_Robot 2:493402568a5e 417 int _pRow;
Yo_Robot 2:493402568a5e 418
Yo_Robot 2:493402568a5e 419 /**Last Element Col position in Matrix*/
Yo_Robot 2:493402568a5e 420 int _pCol;
Yo_Robot 2:493402568a5e 421
Yo_Robot 0:3abd8c2d7c34 422 };
Yo_Robot 0:3abd8c2d7c34 423
Yo_Robot 2:493402568a5e 424 #endif /* MATRIX_H */
Yo_Robot 2:493402568a5e 425