Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RoboticArm DXL_SDK_Porting_Test
Fork of Matrix by
Revision 6:3f01dc2d77f1, committed 2017-02-02
- Comitter:
- stanley1228
- Date:
- Thu Feb 02 04:28:35 2017 +0000
- Parent:
- 5:a4014ab0a8cf
- Child:
- 7:7a564cf28ab6
- Commit message:
- change matrix.cpp .h
Changed in this revision
| Matrix.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Matrix.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Matrix.cpp Sun Oct 30 16:29:23 2011 +0000
+++ b/Matrix.cpp Thu Feb 02 04:28:35 2017 +0000
@@ -159,7 +159,7 @@
Mat._matrix[i].resize( Mat._nCols );
for( int i = 0; i < Mat._nRows; i++ )
- for( int j = Mat._nCols; j > index; j-- )
+ for( int j = Mat._nCols-1; j > index; j-- )//stanley Mat._nCols =>Mat._nCols-1
Mat._matrix[i][j] = Mat._matrix[i][j - 1];
for( int i = 0; i < Mat._nRows; i++ )
@@ -191,7 +191,7 @@
}else{
for( int i = 0; i < Mat._nRows; i++ )
- for( int j = Col; j < Mat._nCols; j++ )
+ for( int j = Col; j < Mat._nCols-1; j++ ) //stanley Mat._nCols=>Mat._nCols-1
Mat._matrix[i][j] = Mat._matrix[i][j+1];
// If adressing last element of Column,
@@ -204,7 +204,7 @@
//Erase last Column
for( int i = 0; i < Mat._nRows; i++ )
- Mat._matrix[i].reserve(Mat._nCols);
+ Mat._matrix[i].reserve(Mat._nCols); //待理解
}
}
@@ -241,6 +241,8 @@
{
printf( "\n\nERROR:\nRow out of dimmensions @ GetRow\n"
"Nothing Done.\n\n" );
+ Matrix NULL_M( 1, 1 );//暫時這樣stanley
+ return NULL_M;
}else{
@@ -267,6 +269,9 @@
{
printf( "\n\nERROR:\nColumn out of dimmensions.\n"
"Nothing Done.\n\n" );
+ Matrix NULL_M( 1, 1 );//暫時這樣stanley
+ return NULL_M;
+
}else{
Matrix SingleCol( Mat._nRows, 1 );
@@ -362,6 +367,46 @@
}
}
+//stanley
+void Matrix::Vec_ext_1_row(Matrix& Vec,float number)
+{
+
+ //Vec._nRows++;
+
+ if( Vec._nCols > 1 )
+ {
+ printf("\n\nERROR:\nOut of limits of Matrix @ mat.Vec_ext_1_row()");
+
+ }
+ else
+ {
+ for( int i = 0; i < _nRows-1; i++ )//複製前三列
+ _matrix[i][0] = Vec._matrix[i][0];
+
+ _matrix[_nRows-1][0] = number;//最後一列補0
+ }
+}
+
+//stanley
+//[Vec1 vec2 vec3 number]' =>Just get [Vec1 vec2 vec3]
+void Matrix::Vec_export_3_row(Matrix& Vec)
+{
+ _nRows=3;
+
+ if( Vec._nCols > 1 )
+ {
+ printf("\n\nERROR:\nOut of limits of Matrix @ mat.Vec_export_3_row()");
+
+ }
+ else
+ {
+ for( int i = 0; i < _nRows; i++ )//複製前三列
+ _matrix[i][0] = Vec._matrix[i][0];
+
+ }
+
+}
+
/// Adds all elements in matrix and returns the answer.
float Matrix::sum() const
--- a/Matrix.h Sun Oct 30 16:29:23 2011 +0000
+++ b/Matrix.h Thu Feb 02 04:28:35 2017 +0000
@@ -9,11 +9,11 @@
* http://www.gnu.org/licenses/gpl-3.0.html
*
*/
-
+//#include "stdafx.h"
#ifndef MATRIX_H
#define MATRIX_H
-
+using namespace std;
#include <vector>
class MatrixMath;
@@ -369,6 +369,15 @@
void add( int Row, int Col, float number );
+ //stanley
+ //[Vec1 vec2 vec3 number]'
+ void Vec_ext_1_row( Matrix& Vec,float number);
+
+
+ //stanley
+ //[Vec1 vec2 vec3 number]' =>Just get [Vec1 vec2 vec3]
+ void Vec_export_3_row( Matrix& Vec);
+
/** @brief
* Returns the sum of every cell in the Matrix.
*/
@@ -396,10 +405,12 @@
int getRows() const;
+
+
private:
/** 2-D Vector Array*/
- vector < vector<float> > _matrix;
+ std::vector <std::vector<float> > _matrix;
@@ -419,5 +430,4 @@
};
-#endif /* MATRIX_H */
-
+#endif /* MATRIX_H */
\ No newline at end of file
