Matrix Library. v1.6.4
Dependents: Matrix_class Wizardsneverdie TwoTank mbed_multiplex_matrix ... more
Matrix.h@1:48f417da268e, 2011-09-26 (annotated)
- Committer:
- Yo_Robot
- Date:
- Mon Sep 26 03:23:35 2011 +0000
- Revision:
- 1:48f417da268e
- Parent:
- 0:3abd8c2d7c34
- Child:
- 2:493402568a5e
Matrix Class v1.02 - Fixed bugs and typos. Later work will add more functions. This is a replacement for the previous version. Use this one not the old one.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 0:3abd8c2d7c34 | 1 | |
Yo_Robot | 0:3abd8c2d7c34 | 2 | /** |
Yo_Robot | 0:3abd8c2d7c34 | 3 | * @file: Matrix.h |
Yo_Robot | 0:3abd8c2d7c34 | 4 | * @author: Ernesto Palacios |
Yo_Robot | 0:3abd8c2d7c34 | 5 | * Created on 13 de septiembre de 2011, 03:49 PM |
Yo_Robot | 0:3abd8c2d7c34 | 6 | * |
Yo_Robot | 0:3abd8c2d7c34 | 7 | * Develop Under GPL v3.0 License |
Yo_Robot | 0:3abd8c2d7c34 | 8 | * http://www.gnu.org/licenses/gpl-3.0.html |
Yo_Robot | 0:3abd8c2d7c34 | 9 | * |
Yo_Robot | 0:3abd8c2d7c34 | 10 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 11 | |
Yo_Robot | 1:48f417da268e | 12 | #ifndef MATRIX_H |
Yo_Robot | 1:48f417da268e | 13 | #define MATRIX_H |
Yo_Robot | 1:48f417da268e | 14 | |
Yo_Robot | 0:3abd8c2d7c34 | 15 | #include <vector> |
Yo_Robot | 0:3abd8c2d7c34 | 16 | |
Yo_Robot | 1:48f417da268e | 17 | using namespace std; |
Yo_Robot | 0:3abd8c2d7c34 | 18 | |
Yo_Robot | 0:3abd8c2d7c34 | 19 | /** |
Yo_Robot | 0:3abd8c2d7c34 | 20 | * @brief This class is intended to provide basic functionality to a Matrix like vector |
Yo_Robot | 0:3abd8c2d7c34 | 21 | * it's meant for float elements. |
Yo_Robot | 0:3abd8c2d7c34 | 22 | * |
Yo_Robot | 0:3abd8c2d7c34 | 23 | * IMPORTAT: Asignment "=" operator is overloaded so that it resizes the 'lefthand' Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 24 | * to acomodate the Matrix it's been passed. |
Yo_Robot | 0:3abd8c2d7c34 | 25 | * |
Yo_Robot | 0:3abd8c2d7c34 | 26 | * An example of how it works: |
Yo_Robot | 0:3abd8c2d7c34 | 27 | * @code |
Yo_Robot | 0:3abd8c2d7c34 | 28 | * Matrix myMatrix( 3, 4 ); //Declare a 3 Rows by 4 Columns Matrix. |
Yo_Robot | 0:3abd8c2d7c34 | 29 | * |
Yo_Robot | 0:3abd8c2d7c34 | 30 | * myMatrix.Fill(); // Fill the matrix using printf() and scanf(). |
Yo_Robot | 0:3abd8c2d7c34 | 31 | * myMatrix.print(); // Prints the value of the Matrix. printf() |
Yo_Robot | 0:3abd8c2d7c34 | 32 | * |
Yo_Robot | 0:3abd8c2d7c34 | 33 | * Matrix::DeleteCol( myMatrix, 2 ); //Deletes Second Column. (startin' with 1 not 0) |
Yo_Robot | 0:3abd8c2d7c34 | 34 | * myMatrix.print(); // Re-prints Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 35 | * |
Yo_Robot | 0:3abd8c2d7c34 | 36 | * Matrix anotherMatrix (3); // Squared 3x3 Matrix |
Yo_Robot | 1:48f417da268e | 37 | * anotherMatrix = myMatrix; // Re-Sizes 'anotherMatrix' to fit myMatrix and copies data. |
Yo_Robot | 0:3abd8c2d7c34 | 38 | * anotherMatrix += myMatrix; // Adds one-by-one elements and saves to anotherMatrix |
Yo_Robot | 0:3abd8c2d7c34 | 39 | * anotherMatrix.print(); |
Yo_Robot | 0:3abd8c2d7c34 | 40 | * @endcode |
Yo_Robot | 0:3abd8c2d7c34 | 41 | * |
Yo_Robot | 0:3abd8c2d7c34 | 42 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 43 | class Matrix{ |
Yo_Robot | 0:3abd8c2d7c34 | 44 | public: |
Yo_Robot | 0:3abd8c2d7c34 | 45 | |
Yo_Robot | 0:3abd8c2d7c34 | 46 | /// Creates a nex Matrix of Size [ Row x Cols ] |
Yo_Robot | 0:3abd8c2d7c34 | 47 | Matrix( int Rows, int Cols ); |
Yo_Robot | 0:3abd8c2d7c34 | 48 | |
Yo_Robot | 1:48f417da268e | 49 | /// Creats a Square Matrix o Size [ Rows x Rows ] |
Yo_Robot | 0:3abd8c2d7c34 | 50 | Matrix( int Rows ); |
Yo_Robot | 0:3abd8c2d7c34 | 51 | |
Yo_Robot | 0:3abd8c2d7c34 | 52 | |
Yo_Robot | 0:3abd8c2d7c34 | 53 | /// Creates a new Matrix identical in size to an input Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 54 | Matrix( const Matrix &base ); |
Yo_Robot | 0:3abd8c2d7c34 | 55 | |
Yo_Robot | 0:3abd8c2d7c34 | 56 | |
Yo_Robot | 0:3abd8c2d7c34 | 57 | /// Reserves Memory for a New Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 58 | Matrix(); |
Yo_Robot | 0:3abd8c2d7c34 | 59 | |
Yo_Robot | 0:3abd8c2d7c34 | 60 | |
Yo_Robot | 0:3abd8c2d7c34 | 61 | |
Yo_Robot | 1:48f417da268e | 62 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 63 | * This is the '=' Overloaded operator. It RESIZES assigned the matrix. |
Yo_Robot | 0:3abd8c2d7c34 | 64 | * Overwrites all data. To be used Carefully! |
Yo_Robot | 0:3abd8c2d7c34 | 65 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 66 | Matrix& operator = ( const Matrix &rightM ); |
Yo_Robot | 0:3abd8c2d7c34 | 67 | |
Yo_Robot | 0:3abd8c2d7c34 | 68 | |
Yo_Robot | 1:48f417da268e | 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 'false' if different. |
Yo_Robot | 0:3abd8c2d7c34 | 75 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 76 | bool operator == ( const Matrix &rightM ); |
Yo_Robot | 0:3abd8c2d7c34 | 77 | |
Yo_Robot | 0:3abd8c2d7c34 | 78 | |
Yo_Robot | 0:3abd8c2d7c34 | 79 | |
Yo_Robot | 1:48f417da268e | 80 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 81 | * Overload opeartor for the compare Matrices |
Yo_Robot | 0:3abd8c2d7c34 | 82 | * |
Yo_Robot | 0:3abd8c2d7c34 | 83 | * @param rightM |
Yo_Robot | 0:3abd8c2d7c34 | 84 | * @return Boolean 'true' if different |
Yo_Robot | 0:3abd8c2d7c34 | 85 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 86 | bool operator != ( const Matrix &rightM ); |
Yo_Robot | 0:3abd8c2d7c34 | 87 | |
Yo_Robot | 1:48f417da268e | 88 | |
Yo_Robot | 1:48f417da268e | 89 | |
Yo_Robot | 1:48f417da268e | 90 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 91 | * Overload Copmpound assignment. |
Yo_Robot | 0:3abd8c2d7c34 | 92 | * @param rightM |
Yo_Robot | 0:3abd8c2d7c34 | 93 | * @return A new Matrix to be assigned to itself. |
Yo_Robot | 0:3abd8c2d7c34 | 94 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 95 | Matrix& operator += ( const Matrix &rightM ); |
Yo_Robot | 0:3abd8c2d7c34 | 96 | |
Yo_Robot | 0:3abd8c2d7c34 | 97 | |
Yo_Robot | 0:3abd8c2d7c34 | 98 | |
Yo_Robot | 1:48f417da268e | 99 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 100 | * Overload Compund decrease. |
Yo_Robot | 0:3abd8c2d7c34 | 101 | * @param rightM Right hand matrix |
Yo_Robot | 0:3abd8c2d7c34 | 102 | * @return A new Matrix to be assigned to itself |
Yo_Robot | 0:3abd8c2d7c34 | 103 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 104 | Matrix& operator -= ( const Matrix &rightM ); |
Yo_Robot | 0:3abd8c2d7c34 | 105 | |
Yo_Robot | 0:3abd8c2d7c34 | 106 | |
Yo_Robot | 0:3abd8c2d7c34 | 107 | |
Yo_Robot | 1:48f417da268e | 108 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 109 | * Overloads the Plus, returns a new object. |
Yo_Robot | 0:3abd8c2d7c34 | 110 | * @param rightM right side Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 111 | * @return Retuns an instance of the answer. |
Yo_Robot | 0:3abd8c2d7c34 | 112 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 113 | const Matrix operator +( const Matrix &rightM ); |
Yo_Robot | 0:3abd8c2d7c34 | 114 | |
Yo_Robot | 1:48f417da268e | 115 | |
Yo_Robot | 0:3abd8c2d7c34 | 116 | |
Yo_Robot | 1:48f417da268e | 117 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 118 | * Overloads the Minus, returns a new object |
Yo_Robot | 0:3abd8c2d7c34 | 119 | * @param rightM |
Yo_Robot | 0:3abd8c2d7c34 | 120 | * @return Returns an instance of the asnwer |
Yo_Robot | 0:3abd8c2d7c34 | 121 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 122 | const Matrix operator -( const Matrix &rightM ); |
Yo_Robot | 0:3abd8c2d7c34 | 123 | |
Yo_Robot | 1:48f417da268e | 124 | |
Yo_Robot | 1:48f417da268e | 125 | |
Yo_Robot | 0:3abd8c2d7c34 | 126 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 127 | * Returns TRUE if the matrix is zero, FALSE otherwhise |
Yo_Robot | 0:3abd8c2d7c34 | 128 | * @param mat: Matrix to be tested |
Yo_Robot | 0:3abd8c2d7c34 | 129 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 130 | bool isZero(); |
Yo_Robot | 0:3abd8c2d7c34 | 131 | |
Yo_Robot | 0:3abd8c2d7c34 | 132 | |
Yo_Robot | 0:3abd8c2d7c34 | 133 | |
Yo_Robot | 0:3abd8c2d7c34 | 134 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 135 | * Determines weather a Matrix is a Single Column or Row. |
Yo_Robot | 0:3abd8c2d7c34 | 136 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 137 | bool isVector(); |
Yo_Robot | 0:3abd8c2d7c34 | 138 | |
Yo_Robot | 0:3abd8c2d7c34 | 139 | |
Yo_Robot | 1:48f417da268e | 140 | |
Yo_Robot | 1:48f417da268e | 141 | /** @brief |
Yo_Robot | 1:48f417da268e | 142 | * Shatters the matrix into a single Row Vector. |
Yo_Robot | 1:48f417da268e | 143 | * Important: Returns NEW matrix, does no modify existing one. |
Yo_Robot | 1:48f417da268e | 144 | */ |
Yo_Robot | 1:48f417da268e | 145 | Matrix ToPackedVector(); |
Yo_Robot | 0:3abd8c2d7c34 | 146 | |
Yo_Robot | 1:48f417da268e | 147 | |
Yo_Robot | 1:48f417da268e | 148 | |
Yo_Robot | 1:48f417da268e | 149 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 150 | * Determines if two matrices are equal. |
Yo_Robot | 0:3abd8c2d7c34 | 151 | * @param mat1: First Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 152 | * @param mat2: Sencond Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 153 | */ |
Yo_Robot | 1:48f417da268e | 154 | static bool Equals( const Matrix mat1, const Matrix mat2 ); |
Yo_Robot | 0:3abd8c2d7c34 | 155 | |
Yo_Robot | 0:3abd8c2d7c34 | 156 | |
Yo_Robot | 0:3abd8c2d7c34 | 157 | |
Yo_Robot | 0:3abd8c2d7c34 | 158 | /**@brief |
Yo_Robot | 0:3abd8c2d7c34 | 159 | * This Funcrions instanciates a new Row Matrix. Since this is a |
Yo_Robot | 0:3abd8c2d7c34 | 160 | * static function it needs to be assigned to an Empy Matrix Object |
Yo_Robot | 0:3abd8c2d7c34 | 161 | * @param Rows: Number of Rows |
Yo_Robot | 0:3abd8c2d7c34 | 162 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 163 | static Matrix CreateRowMatrix(int Rows); |
Yo_Robot | 0:3abd8c2d7c34 | 164 | |
Yo_Robot | 0:3abd8c2d7c34 | 165 | |
Yo_Robot | 0:3abd8c2d7c34 | 166 | |
Yo_Robot | 1:48f417da268e | 167 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 168 | * This function instanciates a new Column Matrix. Since this is a |
Yo_Robot | 0:3abd8c2d7c34 | 169 | * static function it needs to be assigned to an Empty Matrix object |
Yo_Robot | 0:3abd8c2d7c34 | 170 | * @param Cols: Number of Columns in Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 171 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 172 | static Matrix CreateColumnMatrix(int Cols); |
Yo_Robot | 0:3abd8c2d7c34 | 173 | |
Yo_Robot | 0:3abd8c2d7c34 | 174 | |
Yo_Robot | 0:3abd8c2d7c34 | 175 | |
Yo_Robot | 1:48f417da268e | 176 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 177 | * This STATIC function Clones two Matrices. |
Yo_Robot | 0:3abd8c2d7c34 | 178 | * The Source Matrix can be any Size. |
Yo_Robot | 0:3abd8c2d7c34 | 179 | * The Receip Matrix MUST be just initialized |
Yo_Robot | 0:3abd8c2d7c34 | 180 | * as in: Matrix NewMatrix(); |
Yo_Robot | 0:3abd8c2d7c34 | 181 | * @param Source: Base Matrix to Clone. |
Yo_Robot | 0:3abd8c2d7c34 | 182 | * @param Receip: Destination shell matrix |
Yo_Robot | 0:3abd8c2d7c34 | 183 | */ |
Yo_Robot | 1:48f417da268e | 184 | static void Clone( const Matrix &Source, Matrix &Receip ); |
Yo_Robot | 0:3abd8c2d7c34 | 185 | |
Yo_Robot | 1:48f417da268e | 186 | |
Yo_Robot | 1:48f417da268e | 187 | /** @brief |
Yo_Robot | 1:48f417da268e | 188 | * Invoking this static method will increase a Row in Mat in the desired |
Yo_Robot | 1:48f417da268e | 189 | * position. |
Yo_Robot | 1:48f417da268e | 190 | * The current Row will be moved down to allocate space, and all elements will |
Yo_Robot | 1:48f417da268e | 191 | * be initialized to zero in the new row. |
Yo_Robot | 1:48f417da268e | 192 | * @param Mat: Matrix in wich to insert a Row |
Yo_Robot | 1:48f417da268e | 193 | * @param Row: Number of row to insert, starts with one, not zero. |
Yo_Robot | 1:48f417da268e | 194 | */ |
Yo_Robot | 1:48f417da268e | 195 | static void AddRow( Matrix &Mat, int Row ); |
Yo_Robot | 0:3abd8c2d7c34 | 196 | |
Yo_Robot | 1:48f417da268e | 197 | |
Yo_Robot | 1:48f417da268e | 198 | /** @brief |
Yo_Robot | 1:48f417da268e | 199 | * Invoking this static method will increase a Column in Matrix in the |
Yo_Robot | 1:48f417da268e | 200 | * desired Position. |
Yo_Robot | 1:48f417da268e | 201 | * @param Mat: Matrix in wich to insert a Column |
Yo_Robot | 1:48f417da268e | 202 | * @param Col: Number of column, strats with one, not zero. |
Yo_Robot | 1:48f417da268e | 203 | */ |
Yo_Robot | 1:48f417da268e | 204 | static void AddColumn( Matrix &Mat, int Col ); |
Yo_Robot | 1:48f417da268e | 205 | |
Yo_Robot | 1:48f417da268e | 206 | |
Yo_Robot | 1:48f417da268e | 207 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 208 | * Static Function Deletes Row from Matrix, Static to prevent missuse |
Yo_Robot | 0:3abd8c2d7c34 | 209 | * @param Mat: Matrix to delete Row from |
Yo_Robot | 0:3abd8c2d7c34 | 210 | * @param Row: Number of Row (first Row = 1) |
Yo_Robot | 0:3abd8c2d7c34 | 211 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 212 | static void DeleteRow( Matrix &Mat, int Row ); |
Yo_Robot | 0:3abd8c2d7c34 | 213 | |
Yo_Robot | 0:3abd8c2d7c34 | 214 | |
Yo_Robot | 1:48f417da268e | 215 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 216 | * Static Function Deletes Column from Matrix, it's Static to prevent |
Yo_Robot | 0:3abd8c2d7c34 | 217 | * missuse. |
Yo_Robot | 0:3abd8c2d7c34 | 218 | * Print error and does nothing if out of limits. |
Yo_Robot | 0:3abd8c2d7c34 | 219 | * @param Col: Number of Col to delete (first Col = 1) |
Yo_Robot | 1:48f417da268e | 220 | * @param Mat: Matrix to delete from. |
Yo_Robot | 0:3abd8c2d7c34 | 221 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 222 | static void DeleteCol( Matrix &Mat, int Col ); |
Yo_Robot | 0:3abd8c2d7c34 | 223 | |
Yo_Robot | 0:3abd8c2d7c34 | 224 | |
Yo_Robot | 0:3abd8c2d7c34 | 225 | |
Yo_Robot | 1:48f417da268e | 226 | |
Yo_Robot | 1:48f417da268e | 227 | /** @brief |
Yo_Robot | 1:48f417da268e | 228 | * This method extracts a Row from a Matrix and Saves it in Mat. |
Yo_Robot | 1:48f417da268e | 229 | * If Row is out of the parameters it does nothing, but prints a warning. |
Yo_Robot | 1:48f417da268e | 230 | * @param Row: number of row to extract elements. this->_nRows. |
Yo_Robot | 1:48f417da268e | 231 | * @param Mat: Matrix to resize if neccesaty and save data. |
Yo_Robot | 0:3abd8c2d7c34 | 232 | */ |
Yo_Robot | 1:48f417da268e | 233 | void ExportRow( int Row, Matrix &Mat); |
Yo_Robot | 1:48f417da268e | 234 | |
Yo_Robot | 1:48f417da268e | 235 | |
Yo_Robot | 1:48f417da268e | 236 | |
Yo_Robot | 1:48f417da268e | 237 | |
Yo_Robot | 1:48f417da268e | 238 | |
Yo_Robot | 1:48f417da268e | 239 | |
Yo_Robot | 1:48f417da268e | 240 | |
Yo_Robot | 1:48f417da268e | 241 | /** @brief |
Yo_Robot | 1:48f417da268e | 242 | * This method extracts a Column from a Matrix and saves it to Mat. |
Yo_Robot | 1:48f417da268e | 243 | * If Row is out of the parameters, it does nothing and prints a warning. |
Yo_Robot | 1:48f417da268e | 244 | * @param Col: number of Column to extract elements. this->_nCols. |
Yo_Robot | 1:48f417da268e | 245 | * @param Mat: Matrix to save data to. |
Yo_Robot | 1:48f417da268e | 246 | */ |
Yo_Robot | 1:48f417da268e | 247 | void ExportCol( int Col, Matrix &Mat ); |
Yo_Robot | 0:3abd8c2d7c34 | 248 | |
Yo_Robot | 0:3abd8c2d7c34 | 249 | |
Yo_Robot | 0:3abd8c2d7c34 | 250 | |
Yo_Robot | 1:48f417da268e | 251 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 252 | * This function resizes the Matrix to fit new data. |
Yo_Robot | 0:3abd8c2d7c34 | 253 | * @param Rows: New Number of Rows |
Yo_Robot | 0:3abd8c2d7c34 | 254 | * @param Cols: New numbler of columns |
Yo_Robot | 0:3abd8c2d7c34 | 255 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 256 | void Resize( int Rows, int Cols ); |
Yo_Robot | 0:3abd8c2d7c34 | 257 | |
Yo_Robot | 0:3abd8c2d7c34 | 258 | |
Yo_Robot | 0:3abd8c2d7c34 | 259 | |
Yo_Robot | 0:3abd8c2d7c34 | 260 | /** @brief |
Yo_Robot | 1:48f417da268e | 261 | * Asks user for numbers to fill the Matrix elements, one by one. |
Yo_Robot | 1:48f417da268e | 262 | * It uses printf(); by default the USBTX, USBRX, 9600, 1N8. |
Yo_Robot | 0:3abd8c2d7c34 | 263 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 264 | void FillMatrix(); |
Yo_Robot | 0:3abd8c2d7c34 | 265 | |
Yo_Robot | 0:3abd8c2d7c34 | 266 | |
Yo_Robot | 0:3abd8c2d7c34 | 267 | |
Yo_Robot | 0:3abd8c2d7c34 | 268 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 269 | * Prints the entire Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 270 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 271 | void print(); |
Yo_Robot | 0:3abd8c2d7c34 | 272 | |
Yo_Robot | 0:3abd8c2d7c34 | 273 | |
Yo_Robot | 1:48f417da268e | 274 | |
Yo_Robot | 1:48f417da268e | 275 | /** @brief |
Yo_Robot | 1:48f417da268e | 276 | * Makes all values on Matrix object zero. |
Yo_Robot | 1:48f417da268e | 277 | */ |
Yo_Robot | 1:48f417da268e | 278 | void Clear(); |
Yo_Robot | 0:3abd8c2d7c34 | 279 | |
Yo_Robot | 1:48f417da268e | 280 | |
Yo_Robot | 1:48f417da268e | 281 | /** @brief |
Yo_Robot | 1:48f417da268e | 282 | * Assigns a float number to the matrix in a specified position |
Yo_Robot | 1:48f417da268e | 283 | * Index starts at [1][1]. |
Yo_Robot | 1:48f417da268e | 284 | * |
Yo_Robot | 1:48f417da268e | 285 | * @param number: Number to be set |
Yo_Robot | 1:48f417da268e | 286 | * @param Row: Row of Matrix |
Yo_Robot | 1:48f417da268e | 287 | * @param Col: Column of Matrix |
Yo_Robot | 0:3abd8c2d7c34 | 288 | */ |
Yo_Robot | 1:48f417da268e | 289 | void add( int Row, int Col, float number ); |
Yo_Robot | 1:48f417da268e | 290 | |
Yo_Robot | 0:3abd8c2d7c34 | 291 | |
Yo_Robot | 0:3abd8c2d7c34 | 292 | |
Yo_Robot | 0:3abd8c2d7c34 | 293 | /** @brief |
Yo_Robot | 1:48f417da268e | 294 | * Returns the sum of every cell in the Matrix. |
Yo_Robot | 1:48f417da268e | 295 | */ |
Yo_Robot | 1:48f417da268e | 296 | float sum(); |
Yo_Robot | 1:48f417da268e | 297 | |
Yo_Robot | 1:48f417da268e | 298 | |
Yo_Robot | 1:48f417da268e | 299 | /** @brief |
Yo_Robot | 0:3abd8c2d7c34 | 300 | * Return the number in position [Row],[Col] |
Yo_Robot | 0:3abd8c2d7c34 | 301 | * @param Row = number of row in matrix |
Yo_Robot | 0:3abd8c2d7c34 | 302 | * @param Col = number of Col in matrix |
Yo_Robot | 0:3abd8c2d7c34 | 303 | * @return Num = float number in matrix |
Yo_Robot | 0:3abd8c2d7c34 | 304 | */ |
Yo_Robot | 1:48f417da268e | 305 | float getNumber( int Row, int Col ); |
Yo_Robot | 0:3abd8c2d7c34 | 306 | |
Yo_Robot | 0:3abd8c2d7c34 | 307 | |
Yo_Robot | 0:3abd8c2d7c34 | 308 | |
Yo_Robot | 1:48f417da268e | 309 | /**@brief |
Yo_Robot | 1:48f417da268e | 310 | * Retuns the number of Columns in Matrix |
Yo_Robot | 1:48f417da268e | 311 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 312 | int getCols(); |
Yo_Robot | 0:3abd8c2d7c34 | 313 | |
Yo_Robot | 0:3abd8c2d7c34 | 314 | |
Yo_Robot | 0:3abd8c2d7c34 | 315 | |
Yo_Robot | 1:48f417da268e | 316 | /**@brief |
Yo_Robot | 1:48f417da268e | 317 | *Retruns the number of Rows in Matrix |
Yo_Robot | 1:48f417da268e | 318 | */ |
Yo_Robot | 0:3abd8c2d7c34 | 319 | int getRows(); |
Yo_Robot | 0:3abd8c2d7c34 | 320 | |
Yo_Robot | 0:3abd8c2d7c34 | 321 | |
Yo_Robot | 0:3abd8c2d7c34 | 322 | private: |
Yo_Robot | 0:3abd8c2d7c34 | 323 | |
Yo_Robot | 0:3abd8c2d7c34 | 324 | /** 2-D Vector Array*/ |
Yo_Robot | 0:3abd8c2d7c34 | 325 | vector < vector<float> > _matrix; |
Yo_Robot | 0:3abd8c2d7c34 | 326 | |
Yo_Robot | 0:3abd8c2d7c34 | 327 | /** Number of Rows in Matrix*/ |
Yo_Robot | 1:48f417da268e | 328 | int _nRows; |
Yo_Robot | 0:3abd8c2d7c34 | 329 | |
Yo_Robot | 0:3abd8c2d7c34 | 330 | /**Number of Columns in Matrix*/ |
Yo_Robot | 1:48f417da268e | 331 | int _nCols; |
Yo_Robot | 0:3abd8c2d7c34 | 332 | |
Yo_Robot | 0:3abd8c2d7c34 | 333 | }; |
Yo_Robot | 0:3abd8c2d7c34 | 334 | |
Yo_Robot | 0:3abd8c2d7c34 | 335 | #endif /* MATRIX_H */ |