Matrix Library. v1.6.4

Dependents:   Matrix_class Wizardsneverdie TwoTank mbed_multiplex_matrix ... more

Committer:
Yo_Robot
Date:
Fri Oct 21 03:33:53 2011 +0000
Revision:
3:589fb80932b5
Parent:
2:493402568a5e
Child:
4:c0c8f3edd60e
version 1.6.0.1  just fixed some typos in comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yo_Robot 0:3abd8c2d7c34 1
Yo_Robot 0:3abd8c2d7c34 2 /**
Yo_Robot 3:589fb80932b5 3 * @file Matrix.h
Yo_Robot 3:589fb80932b5 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 3:589fb80932b5 26 * v1.6
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 3:589fb80932b5 40 /// Default Constructor
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 2:493402568a5e 46
Yo_Robot 2:493402568a5e 47 /**@brief This includes the Class to handle Matrix Operations.
Yo_Robot 2:493402568a5e 48 */
Yo_Robot 2:493402568a5e 49 friend class MatrixMath;
Yo_Robot 0:3abd8c2d7c34 50
Yo_Robot 0:3abd8c2d7c34 51
Yo_Robot 2:493402568a5e 52
Yo_Robot 1:48f417da268e 53 /** @brief
Yo_Robot 3:589fb80932b5 54 * Overwrites all data. To be used Carefully!
Yo_Robot 3:589fb80932b5 55 */
Yo_Robot 3:589fb80932b5 56 Matrix& operator = ( const Matrix& rightM );
Yo_Robot 3:589fb80932b5 57
Yo_Robot 3:589fb80932b5 58
Yo_Robot 3:589fb80932b5 59
Yo_Robot 3:589fb80932b5 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 3:589fb80932b5 117 * All elements in matrix are multiplied by (-1).
Yo_Robot 2:493402568a5e 118 * @return A new Matrix object with inverted values.
Yo_Robot 2:493402568a5e 119 */
Yo_Robot 2:493402568a5e 120 const Matrix operator -();
Yo_Robot 2:493402568a5e 121
Yo_Robot 2:493402568a5e 122
Yo_Robot 2:493402568a5e 123
Yo_Robot 2:493402568a5e 124 /**@brief
Yo_Robot 2:493402568a5e 125 * Overload Compound add with scalar.
Yo_Robot 2:493402568a5e 126 * Because the '=' operator checks for self Assign, no extra operations
Yo_Robot 2:493402568a5e 127 * are needed.
Yo_Robot 2:493402568a5e 128 * @return Same Matrix to self Assign.
Yo_Robot 2:493402568a5e 129 */
Yo_Robot 2:493402568a5e 130 friend const Matrix operator +=( Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 131
Yo_Robot 2:493402568a5e 132
Yo_Robot 2:493402568a5e 133
Yo_Robot 2:493402568a5e 134 /**@brief
Yo_Robot 2:493402568a5e 135 * Compound substract with scalar.
Yo_Robot 2:493402568a5e 136 * @return Same matrix to self Assign.
Yo_Robot 2:493402568a5e 137 */
Yo_Robot 2:493402568a5e 138 friend const Matrix operator -=( Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 139
Yo_Robot 2:493402568a5e 140
Yo_Robot 2:493402568a5e 141
Yo_Robot 2:493402568a5e 142 /** @brief
Yo_Robot 2:493402568a5e 143 * Adds two matrices of the same dimensions, element-by-element.
Yo_Robot 2:493402568a5e 144 * If diferent dimensions -> ERROR.
Yo_Robot 2:493402568a5e 145 * @return A new object Matrix with the result.
Yo_Robot 2:493402568a5e 146 */
Yo_Robot 2:493402568a5e 147 friend const Matrix operator +( const Matrix& leftM, const Matrix& rightM);
Yo_Robot 0:3abd8c2d7c34 148
Yo_Robot 0:3abd8c2d7c34 149
Yo_Robot 0:3abd8c2d7c34 150
Yo_Robot 1:48f417da268e 151 /** @brief
Yo_Robot 2:493402568a5e 152 * Adds the given nomber to each element of matrix.
Yo_Robot 2:493402568a5e 153 * Mimic MATLAB operation.
Yo_Robot 2:493402568a5e 154 * @return A new matrix object with the result.
Yo_Robot 2:493402568a5e 155 */
Yo_Robot 2:493402568a5e 156 friend const Matrix operator +( const Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 157
Yo_Robot 2:493402568a5e 158
Yo_Robot 2:493402568a5e 159
Yo_Robot 2:493402568a5e 160 /**@brief
Yo_Robot 2:493402568a5e 161 * Adds the given number to each element in Matrix.
Yo_Robot 2:493402568a5e 162 * @return A new Matrix object with the result.
Yo_Robot 2:493402568a5e 163 */
Yo_Robot 2:493402568a5e 164 friend const Matrix operator +( float number, const Matrix& leftM );
Yo_Robot 2:493402568a5e 165
Yo_Robot 2:493402568a5e 166
Yo_Robot 2:493402568a5e 167
Yo_Robot 2:493402568a5e 168 /**@brief
Yo_Robot 2:493402568a5e 169 * Substracts two matrices of the same size, element-by-element.
Yo_Robot 2:493402568a5e 170 * If different dimensions -> ERROR.
Yo_Robot 2:493402568a5e 171 * @return A new object Matrix with the result.
Yo_Robot 2:493402568a5e 172 */
Yo_Robot 2:493402568a5e 173 friend const Matrix operator -( const Matrix& leftM, const Matrix& rightM );
Yo_Robot 2:493402568a5e 174
Yo_Robot 2:493402568a5e 175
Yo_Robot 2:493402568a5e 176
Yo_Robot 2:493402568a5e 177 /**@brief
Yo_Robot 2:493402568a5e 178 * Substracts each element in Matrix by number.
Yo_Robot 2:493402568a5e 179 * @return A new matrix object with the result.
Yo_Robot 0:3abd8c2d7c34 180 */
Yo_Robot 2:493402568a5e 181 friend const Matrix operator -( const Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 182
Yo_Robot 2:493402568a5e 183
Yo_Robot 2:493402568a5e 184
Yo_Robot 2:493402568a5e 185 /**@brief
Yo_Robot 2:493402568a5e 186 * Substracts each element in Matrix by number
Yo_Robot 2:493402568a5e 187 * @return A new matrix object with the result.
Yo_Robot 2:493402568a5e 188 */
Yo_Robot 2:493402568a5e 189 friend const Matrix operator -( float number, const Matrix& leftM );
Yo_Robot 2:493402568a5e 190
Yo_Robot 2:493402568a5e 191
Yo_Robot 2:493402568a5e 192
Yo_Robot 2:493402568a5e 193 /**
Yo_Robot 2:493402568a5e 194 * Preforms Crossproduct between two matrices.
Yo_Robot 2:493402568a5e 195 * @return
Yo_Robot 2:493402568a5e 196 */
Yo_Robot 2:493402568a5e 197 friend const Matrix operator *( const Matrix& leftM, const Matrix& rightM );
Yo_Robot 2:493402568a5e 198
Yo_Robot 2:493402568a5e 199
Yo_Robot 2:493402568a5e 200
Yo_Robot 2:493402568a5e 201 /**@brief
Yo_Robot 2:493402568a5e 202 * Multiplies a scalar number with each element on Matrix.
Yo_Robot 2:493402568a5e 203 * @return A new object with the result.
Yo_Robot 2:493402568a5e 204 */
Yo_Robot 2:493402568a5e 205 friend const Matrix operator *( const Matrix& leftM, float number );
Yo_Robot 2:493402568a5e 206
Yo_Robot 2:493402568a5e 207
Yo_Robot 2:493402568a5e 208
Yo_Robot 2:493402568a5e 209 /**@brief
Yo_Robot 2:493402568a5e 210 * Multiplies a scalar number with each element on Matrix.
Yo_Robot 2:493402568a5e 211 * @return
Yo_Robot 2:493402568a5e 212 */
Yo_Robot 2:493402568a5e 213 friend const Matrix operator *( float number, const Matrix& leftM );
Yo_Robot 2:493402568a5e 214
Yo_Robot 0:3abd8c2d7c34 215
Yo_Robot 1:48f417da268e 216
Yo_Robot 2:493402568a5e 217 /**@brief
Yo_Robot 2:493402568a5e 218 * Inputs numbres into a Matrix, the matrix needs to be costructed as
Yo_Robot 2:493402568a5e 219 * Matrix( _nRows, _nCols ).
Yo_Robot 2:493402568a5e 220 * This does NOT work on an only declared Matrix such as:
Yo_Robot 2:493402568a5e 221 * Matrix obj;
Yo_Robot 2:493402568a5e 222 * obj << 5; //Error
Yo_Robot 2:493402568a5e 223 * @return
Yo_Robot 2:493402568a5e 224 */
Yo_Robot 2:493402568a5e 225 friend Matrix& operator <<( Matrix& leftM, float number );
Yo_Robot 0:3abd8c2d7c34 226
Yo_Robot 2:493402568a5e 227 /***********************************************************************/
Yo_Robot 0:3abd8c2d7c34 228
Yo_Robot 0:3abd8c2d7c34 229 /** @brief
Yo_Robot 0:3abd8c2d7c34 230 * Returns TRUE if the matrix is zero, FALSE otherwhise
Yo_Robot 0:3abd8c2d7c34 231 * @param mat: Matrix to be tested
Yo_Robot 0:3abd8c2d7c34 232 */
Yo_Robot 0:3abd8c2d7c34 233 bool isZero();
Yo_Robot 0:3abd8c2d7c34 234
Yo_Robot 0:3abd8c2d7c34 235
Yo_Robot 0:3abd8c2d7c34 236
Yo_Robot 0:3abd8c2d7c34 237 /** @brief
Yo_Robot 0:3abd8c2d7c34 238 * Determines weather a Matrix is a Single Column or Row.
Yo_Robot 0:3abd8c2d7c34 239 */
Yo_Robot 0:3abd8c2d7c34 240 bool isVector();
Yo_Robot 0:3abd8c2d7c34 241
Yo_Robot 0:3abd8c2d7c34 242
Yo_Robot 2:493402568a5e 243
Yo_Robot 1:48f417da268e 244 /** @brief
Yo_Robot 1:48f417da268e 245 * Shatters the matrix into a single Row Vector.
Yo_Robot 1:48f417da268e 246 * Important: Returns NEW matrix, does no modify existing one.
Yo_Robot 1:48f417da268e 247 */
Yo_Robot 2:493402568a5e 248 static const Matrix ToPackedVector( const Matrix& Mat );
Yo_Robot 0:3abd8c2d7c34 249
Yo_Robot 1:48f417da268e 250
Yo_Robot 2:493402568a5e 251
Yo_Robot 1:48f417da268e 252 /** @brief
Yo_Robot 2:493402568a5e 253 * Invoking this static method will increase a Row in Mat in the desired
Yo_Robot 1:48f417da268e 254 * position.
Yo_Robot 1:48f417da268e 255 * The current Row will be moved down to allocate space, and all elements will
Yo_Robot 1:48f417da268e 256 * be initialized to zero in the new row.
Yo_Robot 2:493402568a5e 257 * @param Mat: Matrix in wich to insert a Row
Yo_Robot 1:48f417da268e 258 * @param Row: Number of row to insert, starts with one, not zero.
Yo_Robot 2:493402568a5e 259 */
Yo_Robot 2:493402568a5e 260 static void AddRow( Matrix& Mat, int Row );
Yo_Robot 0:3abd8c2d7c34 261
Yo_Robot 2:493402568a5e 262
Yo_Robot 1:48f417da268e 263 /** @brief
Yo_Robot 2:493402568a5e 264 * Invoking this static method will increase a Column in Matrix in the
Yo_Robot 1:48f417da268e 265 * desired Position.
Yo_Robot 1:48f417da268e 266 * @param Mat: Matrix in wich to insert a Column
Yo_Robot 1:48f417da268e 267 * @param Col: Number of column, strats with one, not zero.
Yo_Robot 1:48f417da268e 268 */
Yo_Robot 2:493402568a5e 269 static void AddColumn( Matrix& Mat, int Col );
Yo_Robot 2:493402568a5e 270
Yo_Robot 1:48f417da268e 271
Yo_Robot 1:48f417da268e 272 /** @brief
Yo_Robot 0:3abd8c2d7c34 273 * Static Function Deletes Row from Matrix, Static to prevent missuse
Yo_Robot 0:3abd8c2d7c34 274 * @param Mat: Matrix to delete Row from
Yo_Robot 0:3abd8c2d7c34 275 * @param Row: Number of Row (first Row = 1)
Yo_Robot 0:3abd8c2d7c34 276 */
Yo_Robot 2:493402568a5e 277 static void DeleteRow( Matrix& Mat, int Row );
Yo_Robot 0:3abd8c2d7c34 278
Yo_Robot 0:3abd8c2d7c34 279
Yo_Robot 1:48f417da268e 280 /** @brief
Yo_Robot 0:3abd8c2d7c34 281 * Static Function Deletes Column from Matrix, it's Static to prevent
Yo_Robot 0:3abd8c2d7c34 282 * missuse.
Yo_Robot 0:3abd8c2d7c34 283 * Print error and does nothing if out of limits.
Yo_Robot 0:3abd8c2d7c34 284 * @param Col: Number of Col to delete (first Col = 1)
Yo_Robot 1:48f417da268e 285 * @param Mat: Matrix to delete from.
Yo_Robot 0:3abd8c2d7c34 286 */
Yo_Robot 2:493402568a5e 287 static void DeleteCol( Matrix& Mat, int Col );
Yo_Robot 0:3abd8c2d7c34 288
Yo_Robot 0:3abd8c2d7c34 289
Yo_Robot 0:3abd8c2d7c34 290
Yo_Robot 1:48f417da268e 291
Yo_Robot 1:48f417da268e 292 /** @brief
Yo_Robot 1:48f417da268e 293 * This method extracts a Row from a Matrix and Saves it in Mat.
Yo_Robot 1:48f417da268e 294 * If Row is out of the parameters it does nothing, but prints a warning.
Yo_Robot 1:48f417da268e 295 * @param Row: number of row to extract elements. this->_nRows.
Yo_Robot 2:493402568a5e 296 * @param Mat: Matrix to extract from.
Yo_Robot 2:493402568a5e 297 * @return New Row Matrix.
Yo_Robot 0:3abd8c2d7c34 298 */
Yo_Robot 2:493402568a5e 299 static const Matrix ExportRow( const Matrix& Mat, int row );
Yo_Robot 0:3abd8c2d7c34 300
Yo_Robot 0:3abd8c2d7c34 301
Yo_Robot 0:3abd8c2d7c34 302
Yo_Robot 1:48f417da268e 303 /** @brief
Yo_Robot 2:493402568a5e 304 * This method extracts a Column from a Matrix and returns the Column
Yo_Robot 2:493402568a5e 305 * as a new Matrix.
Yo_Robot 2:493402568a5e 306 * If Row is out of the parameters, it does nothing and prints a warning.
Yo_Robot 2:493402568a5e 307 * @param Col: number of Column to extract elements. this->_nCols.
Yo_Robot 2:493402568a5e 308 * @param Mat: Matrix to extract from.
Yo_Robot 2:493402568a5e 309 * @return New Row Matrix.
Yo_Robot 2:493402568a5e 310 */
Yo_Robot 2:493402568a5e 311 static const Matrix ExportCol( const Matrix& Mat, int col );
Yo_Robot 2:493402568a5e 312
Yo_Robot 2:493402568a5e 313
Yo_Robot 2:493402568a5e 314
Yo_Robot 2:493402568a5e 315 /** @brief
Yo_Robot 2:493402568a5e 316 * This function resizes the Matrix to fit new data or cropped it,
Yo_Robot 2:493402568a5e 317 * to use newly created memory use .add() not << operator.
Yo_Robot 2:493402568a5e 318 * << operator overwites everithing
Yo_Robot 2:493402568a5e 319 *
Yo_Robot 0:3abd8c2d7c34 320 * @param Rows: New Number of Rows
Yo_Robot 0:3abd8c2d7c34 321 * @param Cols: New numbler of columns
Yo_Robot 0:3abd8c2d7c34 322 */
Yo_Robot 0:3abd8c2d7c34 323 void Resize( int Rows, int Cols );
Yo_Robot 0:3abd8c2d7c34 324
Yo_Robot 0:3abd8c2d7c34 325
Yo_Robot 0:3abd8c2d7c34 326
Yo_Robot 0:3abd8c2d7c34 327 /** @brief
Yo_Robot 1:48f417da268e 328 * Asks user for numbers to fill the Matrix elements, one by one.
Yo_Robot 1:48f417da268e 329 * It uses printf(); by default the USBTX, USBRX, 9600, 1N8.
Yo_Robot 0:3abd8c2d7c34 330 */
Yo_Robot 2:493402568a5e 331 virtual void FillMatrix();
Yo_Robot 0:3abd8c2d7c34 332
Yo_Robot 0:3abd8c2d7c34 333
Yo_Robot 0:3abd8c2d7c34 334
Yo_Robot 0:3abd8c2d7c34 335 /** @brief
Yo_Robot 2:493402568a5e 336 * Prints the entire Matrix using standard PRINTF
Yo_Robot 0:3abd8c2d7c34 337 */
Yo_Robot 2:493402568a5e 338 virtual void print();
Yo_Robot 0:3abd8c2d7c34 339
Yo_Robot 0:3abd8c2d7c34 340
Yo_Robot 2:493402568a5e 341
Yo_Robot 1:48f417da268e 342 /** @brief
Yo_Robot 1:48f417da268e 343 * Makes all values on Matrix object zero.
Yo_Robot 2:493402568a5e 344 * Also make posible use the '<<' operator to add elements and keep
Yo_Robot 2:493402568a5e 345 * track of last element added.
Yo_Robot 1:48f417da268e 346 */
Yo_Robot 1:48f417da268e 347 void Clear();
Yo_Robot 0:3abd8c2d7c34 348
Yo_Robot 2:493402568a5e 349
Yo_Robot 1:48f417da268e 350 /** @brief
Yo_Robot 1:48f417da268e 351 * Assigns a float number to the matrix in a specified position
Yo_Robot 1:48f417da268e 352 * Index starts at [1][1].
Yo_Robot 1:48f417da268e 353 *
Yo_Robot 1:48f417da268e 354 * @param number: Number to be set
Yo_Robot 1:48f417da268e 355 * @param Row: Row of Matrix
Yo_Robot 1:48f417da268e 356 * @param Col: Column of Matrix
Yo_Robot 0:3abd8c2d7c34 357 */
Yo_Robot 1:48f417da268e 358 void add( int Row, int Col, float number );
Yo_Robot 1:48f417da268e 359
Yo_Robot 0:3abd8c2d7c34 360
Yo_Robot 0:3abd8c2d7c34 361
Yo_Robot 0:3abd8c2d7c34 362 /** @brief
Yo_Robot 1:48f417da268e 363 * Returns the sum of every cell in the Matrix.
Yo_Robot 1:48f417da268e 364 */
Yo_Robot 1:48f417da268e 365 float sum();
Yo_Robot 1:48f417da268e 366
Yo_Robot 1:48f417da268e 367
Yo_Robot 1:48f417da268e 368 /** @brief
Yo_Robot 0:3abd8c2d7c34 369 * Return the number in position [Row],[Col]
Yo_Robot 0:3abd8c2d7c34 370 * @param Row = number of row in matrix
Yo_Robot 0:3abd8c2d7c34 371 * @param Col = number of Col in matrix
Yo_Robot 0:3abd8c2d7c34 372 * @return Num = float number in matrix
Yo_Robot 0:3abd8c2d7c34 373 */
Yo_Robot 1:48f417da268e 374 float getNumber( int Row, int Col );
Yo_Robot 0:3abd8c2d7c34 375
Yo_Robot 0:3abd8c2d7c34 376
Yo_Robot 2:493402568a5e 377
Yo_Robot 1:48f417da268e 378 /**@brief
Yo_Robot 2:493402568a5e 379 * Retuns the number of Columns in Matrix, index starts at 1.
Yo_Robot 1:48f417da268e 380 */
Yo_Robot 0:3abd8c2d7c34 381 int getCols();
Yo_Robot 0:3abd8c2d7c34 382
Yo_Robot 0:3abd8c2d7c34 383
Yo_Robot 0:3abd8c2d7c34 384
Yo_Robot 1:48f417da268e 385 /**@brief
Yo_Robot 2:493402568a5e 386 *Retruns the number of Rows in Matrix, index starts at 1.
Yo_Robot 1:48f417da268e 387 */
Yo_Robot 0:3abd8c2d7c34 388 int getRows();
Yo_Robot 0:3abd8c2d7c34 389
Yo_Robot 0:3abd8c2d7c34 390
Yo_Robot 0:3abd8c2d7c34 391 private:
Yo_Robot 0:3abd8c2d7c34 392
Yo_Robot 0:3abd8c2d7c34 393 /** 2-D Vector Array*/
Yo_Robot 0:3abd8c2d7c34 394 vector < vector<float> > _matrix;
Yo_Robot 0:3abd8c2d7c34 395
Yo_Robot 2:493402568a5e 396
Yo_Robot 2:493402568a5e 397
Yo_Robot 0:3abd8c2d7c34 398 /** Number of Rows in Matrix*/
Yo_Robot 1:48f417da268e 399 int _nRows;
Yo_Robot 0:3abd8c2d7c34 400
Yo_Robot 0:3abd8c2d7c34 401 /**Number of Columns in Matrix*/
Yo_Robot 1:48f417da268e 402 int _nCols;
Yo_Robot 0:3abd8c2d7c34 403
Yo_Robot 2:493402568a5e 404
Yo_Robot 2:493402568a5e 405
Yo_Robot 2:493402568a5e 406 /**Last Element Row position in Matrix*/
Yo_Robot 2:493402568a5e 407 int _pRow;
Yo_Robot 2:493402568a5e 408
Yo_Robot 2:493402568a5e 409 /**Last Element Col position in Matrix*/
Yo_Robot 2:493402568a5e 410 int _pCol;
Yo_Robot 2:493402568a5e 411
Yo_Robot 0:3abd8c2d7c34 412 };
Yo_Robot 0:3abd8c2d7c34 413
Yo_Robot 2:493402568a5e 414 #endif /* MATRIX_H */
Yo_Robot 2:493402568a5e 415