use from Ernesto Palacios
Dependents: RoboticArm DXL_SDK_Porting_Test
Fork of Matrix by
Diff: Matrix.cpp
- Revision:
- 4:c0c8f3edd60e
- Parent:
- 3:589fb80932b5
- Child:
- 5:a4014ab0a8cf
diff -r 589fb80932b5 -r c0c8f3edd60e Matrix.cpp --- a/Matrix.cpp Fri Oct 21 03:33:53 2011 +0000 +++ b/Matrix.cpp Sat Oct 22 23:19:51 2011 +0000 @@ -51,7 +51,7 @@ _pRow = 0; _pCol = 0; - + } /***********************************************************************/ @@ -82,7 +82,7 @@ /// Returns all elements in Matrix as a single Row vector. const Matrix Matrix::ToPackedVector( const Matrix& Mat ) { - + Matrix Crushed( 1, Mat._nRows * Mat._nCols ); int cont = 0; @@ -103,11 +103,11 @@ /// To add (Insert) a Single Row to a Matrix. -void Matrix::AddRow(Matrix& Mat, int Row) +void Matrix::AddRow(Matrix& Mat, int index) { - --Row; + --index; - if( Row > Mat._nRows + 1) + if( index > Mat._nRows + 1) { printf("\n\nERROR:\nRow out of Limits @ AddRow()\n"); @@ -118,22 +118,33 @@ Mat._matrix[ Mat._nRows - 1 ].resize( Mat._nCols ); - for( int i = Mat._nRows - 1; i > Row; i-- ) + for( int i = Mat._nRows - 1; i > index; i-- ) for( int j = 0; j < Mat._nCols; j++ ) Mat._matrix[i][j] = Mat._matrix[i - 1][j]; for( int j = 0; j < Mat._nCols; j++ ) - Mat._matrix[Row][j] = 0.0; + Mat._matrix[index][j] = 0.0; } } +void Matrix::AddRow(Matrix& Receip, const Matrix& Row, int index) +{ + Matrix::AddRow( Receip, index ); //Make Room + + --index; + for( int i; i < Receip._nCols; i++ ) + Receip._matrix[index][i] = Row._matrix[0][i]; //Copy Data. + +} + + /// To add (Insert) a single Column to a Matrix -void Matrix::AddColumn( Matrix& Mat, int Col ) +void Matrix::AddCol( Matrix& Mat, int index ) { - --Col; + --index; - if( Col > Mat._nCols + 1 ) + if( index > Mat._nCols + 1 ) { printf("\n\nERROR:\nRow out of Limits on AddCol()\n"); @@ -145,16 +156,26 @@ Mat._matrix[i].resize( Mat._nCols ); for( int i = 0; i < Mat._nRows; i++ ) - for( int j = Mat._nCols; j > Col; j-- ) + for( int j = Mat._nCols; j > index; j-- ) Mat._matrix[i][j] = Mat._matrix[i][j - 1]; for( int i = 0; i < Mat._nRows; i++ ) - Mat._matrix[i][Col] = 0.0; + Mat._matrix[i][index] = 0.0; } } +void Matrix::AddCol(Matrix& Receip, const Matrix& Row, int index) +{ + Matrix::AddCol( Receip, index ); // Make Rom + + --index; + for( int i = 0; i < Receip._nRows; i++ ) + Receip._matrix[i][index] = Row._matrix[i][0]; //Copy Data. +} + + /// Delete a Single Column From Matrix. void Matrix::DeleteCol( Matrix& Mat, int Col) { @@ -222,7 +243,7 @@ Matrix SingleRow( 1 , Mat._nCols ); SingleRow.Clear(); - + for( int j = 0; j < Mat._nCols; j++ ) SingleRow._matrix[0][j] = Mat._matrix[row][j]; @@ -238,7 +259,7 @@ const Matrix Matrix::ExportCol( const Matrix& Mat, int col ) { --col; - + if( col > Mat._nCols ) { printf( "\n\nERROR:\nColumn out of dimmensions.\n" @@ -248,10 +269,10 @@ Matrix SingleCol( Mat._nRows, 1 ); for(int i = 0; i < Mat._nRows; i++ ) SingleCol._matrix[i][0] = Mat._matrix[i][col]; - + SingleCol._pCol = 0; SingleCol._pRow = SingleCol._nRows; - + return SingleCol; } }