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