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