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