📄 matrixdata.h
字号:
/**
Set the values of a matrix row equal to the values of a vector. The
row is specified by a 0 based row index. If the matrix row and vector
do not have the same size then the maximum number of elements possible
are assigned from the vector to the matrix row.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
// Matrix1 after running Example program
0 1 2 3 4
1 2 3 4 5
-99 -99 -99 -99 -99
3 4 5 6 7
4 5 6 7 8
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
vector v = {-99,-99,-99,-99,-99};
mat.SetRow( v, 2);
Parameters:
vb=Vector whose values are assigned to the row
nIndexRow=Specifies the 0 based offset or row index of the row in the matrix
Return:
Returns 0 if successful and the vector size matches the matrix row size,
otherwise returns the size of the matrix row minus the size of the vector.
SeeAlso:
matrixbase::GetRow, matrixbase::SetColumn, matrixbase::GetColumn, matrixbase::GetAsVector, matrixbase::SetByVector
*/
int SetRow(vectorbase &vb, UINT wIndexRow); // Set the values of a matrix row equal to the values of a vector.
/**
Get the values of a matrix column and assign them to a vector. The
column is specified by a 0 based column index. If the matrix column
and vector do not have the same size then the vector is dynamically
resized.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
vector v1;
mat.GetColumn( v1, 2); // v1 = {2,3,4,5,6}
Parameters:
vb=Vector used to get the matrix column values
nIndexCol=Specifies the 0 based offset or column index of the column in the matrix
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::SetColumn, matrixbase::GetRow, matrixbase::SetRow, matrixbase::GetAsVector, matrixbase::SetByVector
*/
BOOL GetColumn(vectorbase &vb, UINT wIndexCol); // Get the values of a matrix column and assign them to a vector.
/**
Get the values of a matrix row and assign them to a vector. The row
is specified by a 0 based row index. If the matrix row and vector
do not have the same size then the vector is dynamically resized.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
vector v1;
mat.GetRow( v1, 4); // v1 = {4,5,6,7,8}
Parameters:
vb=Vector used to get the matrix row values
nIndexRow=Specifies the 0 based offset or row index of the row in the matrix
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::SetRow, matrixbase::GetColumn, matrixbase::SetColumn, matrixbase::GetAsVector, matrixbase::SetByVector
*/
BOOL GetRow(vectorbase &vb, UINT wIndexRow); // Get the values of a matrix row and assign them to a vector.
/**
Get the values of an entire matrix and assign them to a vector. If
the matrix and vector do not have the number of elements then the
vector is dynamically resized.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
vector v1;
mat.GetAsVector( v1, 4); // v1 = {0,1,2,3,4,1,2,3,4,5,2,3,4,5,6,3,4,5,6,7,4,5,6,7,8}
Parameters:
vb=Vector used to get the matrix values
bByRow=Use Row order if TRUE otherwise use Column order
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::SetByVector, matrixbase::GetRow, matrixbase::SetRow, matrixbase::GetColumn, matrixbase::SetColumn
*/
BOOL GetAsVector(vectorbase &vb, BOOL bByRow = TRUE); // Get the values of an entire matrix and assign them to a vector.
/**
Set the values of a matrix equal to the values of a vector. If the
matrix has more elements than the vector then vector values are
assigned until they are exausted and the remaining matrix values
are left untouched. If the vector has more elements than the matrix
then vector values are assigned to the last element of the matrix
and the remaining elements of the vector are ignored.
Example:
// Assumes 5 x 5 Matrix1 window in Origin
Matrix mat("Matrix1");
vector v1 = {0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4};
mat.SetByVector( v1, FALSE); // Use Column order
// Results in Matrix1
// 0 0 0 0 0
// 1 1 1 1 1
// 2 2 2 2 2
// 3 3 3 3 3
// 4 4 4 4 4
Parameters:
vb=Vector used to set the matrix values
bByRow=Use Row order if TRUE otherwise use Column order
Return:
0 if successful and the number of elements in the vector is the same as the number of elements
in the matrix otherwise the number of elements in the matrix minus the number of elements in the
vector is returned.
SeeAlso:
matrixbase::GetAsVector, matrixbase::SetRow, matrixbase::GetRow, matrixbase::SetColumn, matrixbase::GetColumn
*/
int SetByVector(vectorbase &vb, BOOL bByRow = TRUE); // Set the values of a matrix equal to the values of a vector.
/**
Re-order a matrix from Column order to Row order or from Row order
to Column order.
Sample Data:
// Matrix1 is 5 x 3 with following data
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
// Matrix1 after running Example program
1 1 1
1 1 2
2 2 2
2 3 3
3 3 3
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.Reorder();
Parameters:
bRowOrder=If TRUE re-order to Row order and if FALSE re-order to Column order
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::FlipHorizontal, matrixbase::FlipVertical, matrixbase::Rotate, matrixbase::Transpose
*/
BOOL Reorder(BOOL bRowOrder = TRUE); // Re-order a matrix from Column order to Row order or from Row order to Column order.
/**
Transpose a matrix. Rows become columns and columns become rows.
Sample Data:
// Matrix1 is 5 x 3 with following data
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
// Matrix1 after running Example program
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.Transpose();
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::FlipHorizontal, matrixbase::FlipVertical, matrixbase::Rotate, matrixbase::Transpose
*/
BOOL Transpose(); // Transpose a matrix.
/**
Multiply two matrices element by element placing the result in this
matrix. The underlying base type of the matrix passed as an argument
must be "less than or equal" to the underlying base type of this matrix.
The matrices must have the same size.
Example:
matrix<double> m1(2,2) = {{0,1},{2,3}}, m2(2,2) = {{4,5},{6,7}};
m2.DotMultiply( m1 );
printf( "m2[0][0]=%g\tm2[0][1]=%g\n", m2[0][0], m2[0][1] );
printf( "m2[1][0]=%g\tm2[1][1]=%g\n", m2[1][0], m2[1][1] );
Parameters:
mb=Input matrix which is multiplied with this matrix.
Return:
Returns TRUE on success and FALSE on Failure.
SeeAlso:
matrixbase::DotDivide, matrixbase::DotPower, matrixbase::Cross
*/
BOOL DotMultiply(matrixbase &mb); // Multiply two matrices element by element.
/**
Divide this matrix by another matrix on an element by element basis
placing the result in this matrix. The underlying base type of the
matrix passed as an argument must be "less than or equal" to the underlying
base type of this matrix. The matrices must have the same size.
Example:
matrix<double> m2(2,2) = {{15,12},{9,6}}, m1(2,2) = {{5,4},{3,2}};
m2.DotDivide( m1 );
printf( "m2[0][0]=%g\tm2[0][1]=%g\n", m2[0][0], m2[0][1] );
printf( "m2[1][0]=%g\tm2[1][1]=%g\n", m2[1][0], m2[1][1] );
Parameters:
mb=The input divisor matrix which is divided into this matrix
Return:
Returns TRUE on success and FALSE on Failure.
SeeAlso:
matrixbase::DotMultiply, matrixbase::DotPower, matrixbase::Cross
*/
BOOL DotDivide(matrixbase &mb); // Divide this matrix by another matrix.
/**
Raise this matrix to the power of another matrix on an element by element
basis placing the result in this matrix. The underlying base type of the
matrix passed as an argument must be "less than or equal" to the underlying
base type of this matrix. The matrices must have the same size.
Example:
matrix<double> m2(2,2) = {{16,32},{2,3}}, m1(2,2) = {{0.5,0.6},{3,2}};
m2.DotPower( m1 );
printf( "m2[0][0]=%g\tm2[0][1]=%g\n", m2[0][0], m2[0][1] );
printf( "m2[1][0]=%g\tm2[1][1]=%g\n", m2[1][0], m2[1][1] );
Parameters:
mb=Input matrix to which this matrix is raised (the exponents)
Return:
Returns TRUE on success and FALSE on Failure.
SeeAlso:
matrixbase::DotDivide, matrixbase::DotMultiply, matrixbase::Cross
*/
BOOL DotPower(matrixbase &mb); // Raise this matrix to the power of another matrix.
/**
Sort a matrix in row order (across rows from top/left to bottom/right). The matrix
1 5 9 1 2 3
2 6 10 4 5 6
3 7 11 7 8 9
4 8 12 would become the matrix 10 11 12 after sorting. This function does not
maintain row wise integrity.
Example:
// Assumes Matrix1 window in Origin with unsorted data
Matrix mat("Matrix1");
mat.Sort();
Parameters:
bAscending=Sort in ascending order if TRUE otherwise sort in descending order
*/
void Sort(BOOL bAscending = TRUE);
/**
Get the maximum cell value in the matrix (as a double).
Example:
// Assumes Matrix1 window in Origin
double dMax;
Matrix mat("Matrix1");
dMax = mat.GetMax();
Return:
Returns the maximum cell value in the matrix (as a double).
SeeAlso:
matrixbase::GetMin, matrixbase::GetMean, matrixbase::GetMedian
*/
double GetMax(); // Returns the maximum cell value in the matrix.
/**
Get the minimum cell value in the matrix (as a double).
Example:
// Assumes Matrix1 window in Origin
double dMin;
Matrix mat("Matrix1");
dMin = mat.GetMin();
Return:
Returns the minimum cell value in the matrix (as a double).
SeeAlso:
matrixbase::GetMax, matrixbase::GetMean, matrixbase::GetMedian
*/
double GetMin();
/**
Get the median cell value of the matrix (as a double). If there are an even
number N of cells in the matrix the average of the N/2 and (N+1)/2 sorted
cell values is returned.
Example:
// Assumes Matrix1 window in Origin
double dMedian;
Matrix mat("Matrix1");
dMedian = mat.GetMedian();
Return:
Returns the median cell value of the matrix (as a double).
SeeAlso:
matrixbase::GetMean, matrixbase::GetMin, matrixbase::GetMax
*/
double GetMedian();
/**
Get the mean cell value of the matrix (as a double).
Example:
// Assumes Matrix1 window in Origin
double dMean;
Matrix mat("Matrix1");
dMean = mat.GetMean();
Return:
Returns the mean cell value of the matrix (as a double).
SeeAlso:
matrixbase::GetMedian, matrixbase::GetMin, matrixbase::GetMax
*/
double GetMean();
/**
Remove any row in the matrix that consists entirely of missing values
(i.e. remove empty rows). Optionally remove any row that contains one
or more missing values. This function is useful for removing missing
values from data and for determining whether or not analysis can
logically proceed on data that is paired row wise.
Example:
// Assumes Matrix1 window in Origin
int nRowIndex;
Matrix mat("Matrix1");
nRowIndex = mat.RemoveEmptyRows();
Parameters:
bOnlyRemoveEmptyRows=When TRUE only remove rows consisting entirely of missing values. When FALSE
remove all rows containing one or more missing values
Returns:
Returns -1 * the row number (1 based offset) of the first row that contains a missing value but that
does not consist entirely of missing values (the first row that contains a missing value but that is not
empty) otherwise the number of rows removed is returned.
*/
int RemoveEmptyRows(BOOL bOnlyRemoveEmptyRows = TRUE);
/**
Shrink this matrix by averaging cell values together according to the
column and row shrink factors. This is similar to the LabTalk mat.Shrink() method.
Example:
matrix m1;
m1.SetSize( 15, 12 );
m1.Shrink( 3, 5 );
ASSERT( m1.GetNumCols()==4 );
ASSERT( m1.GetNumRows()==3 );
Parameters:
dColShrinkFactor=column shrink factor
dRowShrinkFactor=row shrink factor
Returns:
Returns TRUE on successful exit and FALSE on failure.
*/
BOOL Shrink( int nColShrinkFactor, int nRowShrinkFactor );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -