In file DMatrix.h:

class CDMatrix: public virtual CVisDMatrix

Matrix class with double precision.

Inheritance:


Public Methods

[more]DIVAMatrixExport void Col (int i, CDVector& vCol) const
Return the i-th column of the matrix.
[more]DIVAMatrixExport void CombVert (CVisDMatrix &Top, CVisDMatrix &Bottom)
Composes the matrix of Top and Bottom (on top of each other).
[more]DIVAMatrixExport void Diag (const CDVector &vec)
Make the matrix a diagonal matrix containing 'vec'.
[more]DIVAMatrixExport void ElementDivide (const CDMatrix& matrix)
Element-wise matrix division.
[more]DIVAMatrixExport void ElementMultiply (const CDMatrix& matrix)
Element-wise matrix multiply.
[more]DIVAMatrixExport void Eq (const double B, CDMatrix& C ) const
Element wise equal to. Comparison of a matrix and a double.
[more]DIVAMatrixExport void Eq ( const CDMatrix& B, CDMatrix& C ) const
Element wise equal to. Comparison of two matrices.
[more]DIVAMatrixExport void Eye ()
Converts the matrix in the identity matrix.
[more]DIVAMatrixExport void FlipLR ()
Flip matrix in left/right direction.
[more]DIVAMatrixExport void FlipUD ()
Flip matrix in up/down direction.
[more]DIVAMatrixExport void FromFile (const CDString & sFilename)
Reads a matrix from disk in binary format.
[more]DIVAMatrixExport void FromFile ( FILE *fh )
Reads a matrix from disk in binary format.
[more]DIVAMatrixExport void FromMatlab (const CDString& sFilename, const CDString& sName)
Reads a matrix from disk in MatLab (.m) format.
[more]DIVAMatrixExport void Ge (const double B, CDMatrix& C ) const
Element wise greater than or equal. Comparison of a matrix and a double.
[more]DIVAMatrixExport void Ge ( const CDMatrix& B, CDMatrix& C ) const
Element wise greater than or equal. Comparison of two matrices.
[more]DIVAMatrixExport void Gt ( const CDMatrix& B, CDMatrix& C ) const
Element wise greater than. Comparison of two matrices.
[more]DIVAMatrixExport void Gt (const double B, CDMatrix& C ) const
Element wise greater than. Comparison of a matrix and a double.
[more]DIVAMatrixExport void Kron (CDMatrix &mX, CDMatrix &mY)
Forms the Kronecker tensor product of two matrices.
[more]DIVAMatrixExport void Le (const double B, CDMatrix& C ) const
Element wise less than or equal. Comparison of a matrix and a double.
[more]DIVAMatrixExport void Le ( const CDMatrix& B, CDMatrix& C ) const
Element wise less than or equal. Comparison of two matrices.
[more]DIVAMatrixExport void Log ()
Takes the natural logarithm (base e=2.71..) of each matrix element.
[more]DIVAMatrixExport void Lt (const double B, CDMatrix& C ) const
Element wise less than. Comparison of a matrix and a double.
[more]DIVAMatrixExport void Lt ( const CDMatrix& B, CDMatrix& C ) const
Element wise less than. Comparison of two matrices.
[more]DIVAMatrixExport double Mean () const
Calcs the mean value of the matrix.
[more]DIVAMatrixExport void MeanCol (CDVector& vMean) const
Calc the mean of each column into a vector.
[more]DIVAMatrixExport void Ne ( const CDMatrix& B, CDMatrix& C ) const
Element wise not equal to. Comparison of two matrices.
[more]DIVAMatrixExport void Ne (const double B, CDMatrix& C ) const
Element wise not equal to. Comparison of a matrix and a double.
[more]DIVAMatrixExport void OneWayANOVA (double& dZ, int& nDFModel, int& nDFError) const
One-way analysis of variance (ANOVA).
[more]DIVAMatrixExport void OuterProduct (const CDVector &v1, const CDVector &v2)
Forms the outer product of two vectors.
[more]DIVAMatrixExport void Rand ()
Uniformly distributed random numbers.
[more]DIVAMatrixExport void Row (int i, CDVector& vRow) const
Return the i-th row of the matrix.
[more]DIVAMatrixExport void Sqr ()
Takes the power of two of each element.
[more]DIVAMatrixExport void Sqrt ()
Takes the square root of each element.
[more]DIVAMatrixExport double Std () const
Calc the standard diviation of the matrix.
[more]DIVAMatrixExport void StdCol (CDVector& vStd) const
Calc the standard deviation of each column into a vector.
[more]DIVAMatrixExport double Sum () const
Calc the total sum of the matrix.
[more]DIVAMatrixExport void SumCol (CDVector& vSum) const
Calc the sum of each column into a vector.
[more]DIVAMatrixExport void TTest ( const int iCol1, const int iCol2, double& dZ, int& nDF ) const
Student's T-test.
[more]DIVAMatrixExport void ToFile ( FILE *fh ) const
Writes the matrix to disk in binary format.
[more]DIVAMatrixExport void ToFile (const CDString & sFilename) const
Writes the matrix to disk in binary format.
[more]DIVAMatrixExport void ToLaTeX ( const CDString& sFilename, const CDString& sVarName, const CDString& sComment, bool fWriteAsTable, const CDString& sNumFmt, const CDString& sBracketType, bool fAppend ) const
Writes the matrix in LaTeX format. Throws: CVisError.
[more]DIVAMatrixExport void ToMatlab ( const CDString& sFilename, const CDString& sName, const CDString& sComment, bool fAppend) const
Writes the matrix to disk in MatLab (.m) format.
[more]DIVAMatrixExport CDString ToString () const
Returns a string representing the matrix.
[more]DIVAMatrixExport void TriL ( CDMatrix &matrix, const int K ) const
Extract lower triangular part of matrix.
[more]DIVAMatrixExport void TriU ( CDMatrix &matrix, const int K ) const
Extract upper triangular part of matrix.
[more]DIVAMatrixExport double Var () const
Calc the variance of the matrix.
[more]DIVAMatrixExport void VarCol (CDVector& vVar) const
Calc the variance of each column into a vector.
[more]DIVAMatrixExport CDMatrix& operator= (double value)
Assignment operator.
[more]DIVAMatrix.h DIVAMatrixExport CDMatrix& operator= (const CVisDMatrix &mat)
Assignment operator.
[more]DIVAMatrixExport CDMatrix& operator= (const CDMatrix &mat)
Assignment operator.


Documentation

Matrix class with double precision based upon the VisSDK matrix class CVisDMatrix.

oDIVAMatrixExport void Col(int i, CDVector& vCol) const

Return the i-th column of the matrix. The vector will be resized if it doesn't have the right length.

Alternatively, one could use the more costly CVisDVector CVisDMatrix::Row(int r) method.

To set the i-th col use: void CVisDMatrix::SetColumn(int c, const CVisDVector &v)

Returns:
Nothing.
Parameters:
i - The column number.
vCol - Output vector;
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void CombVert(CVisDMatrix &Top, CVisDMatrix &Bottom)

Composes the matrix of Top and Bottom (on top of each other).

Returns:
Nothing.
Parameters:
Top - Matrix to be placed in the top of this matrix.
Bottom - Matrix to be placed in the bottom of this matrix.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void Diag(const CDVector &vec)

This function transforms the matrix into a diagonal matrix, with the values of 'vec' in the diagonal.

Returns:
Nothing.
Parameters:
vec - Vector to place in the diagonal.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void ElementDivide(const CDMatrix& matrix)

Divide each element in the matrix with the corresponding element of the input matrix.

Returns:
Nothing.
Author:
Rune Fisker
Version:
5-1-1999

oDIVAMatrixExport void ElementMultiply(const CDMatrix& matrix)

Multiply each element in the matrix with the corresponding element of the input matrix.

Returns:
Nothing.
Author:
Rune Fisker
Version:
5-1-1999

oDIVAMatrixExport void Eq(const double B, CDMatrix& C ) const

Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) == B C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
6-12-2000

oDIVAMatrixExport void Eq( const CDMatrix& B, CDMatrix& C ) const

Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) == B(i,j) C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Eye()

Converts the matrix in the identity matrix - i.e. zeros all-over except the ones in the diagonal.

Returns:
Nothing.
Author:
Rune Fisker
Version:
5-1-1999

oDIVAMatrixExport void FlipLR()

FlipLR modifies the matrix with row preserved and columns flipped in the left/right direction.

Returns:
Nothing.
Author:
Mikkel B. Stegmann
Version:
3-9-2001
See Also:
FlipUD

oDIVAMatrixExport void FlipUD()

FlipUD(X) modifies the matrix with columns preserved and rows flipped in the up/down direction.

Returns:
Nothing.
Author:
Mikkel B. Stegmann
Version:
3-9-2001
See Also:
FlipLR

oDIVAMatrixExport void FromFile(const CDString & sFilename)

Reads a matrix from disk in binary format, as written from CDMatrix::ToFile().

The matrix is resizew if it doesn't fit the disk matrix.

Returns:
Nothing.
Parameters:
sFilename - Input file name.
Author:
Mikkel B. Stegmann
Version:
3-14-2000
See Also:
ToFile

oDIVAMatrixExport void FromFile( FILE *fh )

Reads a matrix from disk in binary format (from the current position of the file pointer), as written from CDMatrix::ToFile().

The matrix is resizew if it doesn't fit the disk matrix.

Returns:
Nothing.
Parameters:
fh - Open file handle.
Author:
Mikkel B. Stegmann
Version:
3-14-2000
See Also:
ToFile

oDIVAMatrixExport void FromMatlab(const CDString& sFilename, const CDString& sName)

Reads a matrix from disk in MatLab (.m) format into 'this'.

Notice that this should be used for storage a (really) large matrices, due to the computational and i/o overhead induced by the simple MatLab text format.

Also, remember that MatLab can't read (.m) files with lines longer than 4096 bytes.

If no communication with MatLab is needed, but merely to/from disk functionality within a DIVA program, it is suggested to use the fast binary i/o methods ToFile() and FromFile().

Returns:
Nothing.
Parameters:
sFilename - Input file name.
sName - The name to search for (and load) inside the matlab file.
Author:
Henrik Aanęs
Version:
14-7-1999

oDIVAMatrixExport void Ge(const double B, CDMatrix& C ) const

Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) >= B C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Ge( const CDMatrix& B, CDMatrix& C ) const

Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) <= B(i,j) C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Gt(const double B, CDMatrix& C ) const

Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) > B C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Gt( const CDMatrix& B, CDMatrix& C ) const

Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) > B(i,j) C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Kron(CDMatrix &mX, CDMatrix &mY)

Forms the Kronecker tensor product of two matrices. The result is placed in this.

Returns:
Nothing.
Author:
Rune Fisker
Version:
5-1-1999

oDIVAMatrixExport void Le(const double B, CDMatrix& C ) const

Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) <= B C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Le( const CDMatrix& B, CDMatrix& C ) const

Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) <= B(i,j) C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Log()

Takes the natural logarithm (base e=2.71..) of each matrix element.

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Lt(const double B, CDMatrix& C ) const

Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) < B C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Lt( const CDMatrix& B, CDMatrix& C ) const

Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) < B(i,j) C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport double Mean() const

Calcs the mean value of the matrix.

Returns:
The mean value.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void MeanCol(CDVector& vMean) const

Calc the mean of each column into a vector. The vector will be resized if it doesn't have the right length.

Returns:
Nothing.
Parameters:
vMean - Output vector.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void Ne(const double B, CDMatrix& C ) const

Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) != B C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void Ne( const CDMatrix& B, CDMatrix& C ) const

Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0.

C(i,j) = 1 if A(i,j) != B(i,j) C(i,j) = 0 else

Returns:
Nothing.
Author:
Lars Pedersen
Version:
7-12-2000

oDIVAMatrixExport void OneWayANOVA(double& dZ, int& nDFModel, int& nDFError) const

Determination of the fluctuations observed in a sample, and their dependencies in the form of a one-way analysis of variance (ANOVA).

Returns:
Nothing.
Parameters:
dZ -
nDFModel -
nDFError -
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void OuterProduct(const CDVector &v1, const CDVector &v2)

Forms the outer product of two vectors and store the result in this. If the matrix does have the correct size, it will be resized.

Returns:
Nothing.
Parameters:
v1 - Input vector.
v2 - Input vector.
Author:
Mikkel B. Stegmann
Version:
3-16-2001

oDIVAMatrixExport void Rand()

Inserts uniformly distributed random numbers in the range [0;1].

Returns:
Nothing.
Author:
Mikkel B. Stegmann
Version:
3-9-2001

oDIVAMatrixExport void Row(int i, CDVector& vRow) const

Return the i-th row of the matrix. The vector will be resized if it doesn't have the right length.

Notice that due to the row major nature of matrices, row read/writes are *much* faster than col read/writes.

Alternatively, one could use the more costly CVisDVector CVisDMatrix::Row(int r) method.

To set the i-th row use: void CVisDMatrix::SetRow(int r, const CVisDVector &v)

Returns:
Nothing.
Parameters:
i - The row number.
vRow - Output vector;
Author:
Mikkel B. Stegmann
Version:
3-14-2001

oDIVAMatrixExport void Sqr()

Takes the power of two of each element.

Returns:
Nothing.
Author:
Rune Fisker
Version:
5-1-1999

oDIVAMatrixExport void Sqrt()

Takes the square root of each element.

Returns:
Nothing.
Author:
Rune Fisker
Version:
5-1-1999

oDIVAMatrixExport double Std() const

Calc the standard diviation of the matrix.

Returns:
The standard diviation value.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void StdCol(CDVector& vStd) const

Calc the standard deviation of each column into a vector. The vector will be resized if it doesn't have the right length.

Returns:
Nothing.
Parameters:
vStd - Output vector.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport double Sum() const

Calc the total sum of the matrix.

Returns:
The sum.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void SumCol(CDVector& vSum) const

Calc the sum of each column into a vector. The vector will be resized if it doesn't have the right length.

Returns:
Nothing.
Parameters:
vSum - Output vector.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void TTest( const int iCol1, const int iCol2, double& dZ, int& nDF ) const

Student's T-test.

Returns:
Nothing.
Parameters:
iCol1 -
iCol2 -
dZ -
nDF -
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void ToFile(const CDString & sFilename) const

Writes the matrix to disk in binary format. The dimensions are saved as two doubles (!!?) (rows,cols) in the start.

Modified: Mikkel B. Stegmann 14/3-00

Returns:
Nothing.
Parameters:
sFilename - Input file name.
Author:
Henrik Aanęs
Version:
7-22-1999
See Also:
FromFile

oDIVAMatrixExport void ToFile( FILE *fh ) const

Writes the matrix to disk in binary format. The dimensions are saved as two doubles (!!?) (rows,cols) in the start. The matrix is written to the binary file 'fh' at the current position of the file pointer.

Modified: Mikkel B. Stegmann 14/3-00

Returns:
Nothing.
Parameters:
fh - Open file handle.
Author:
Mikkel B. Stegmann
Version:
4-14-1999
See Also:
FromFile

oDIVAMatrixExport void ToLaTeX( const CDString& sFilename, const CDString& sVarName, const CDString& sComment, bool fWriteAsTable, const CDString& sNumFmt, const CDString& sBracketType, bool fAppend ) const

Writes the matrix in LaTeX format. Throws: CVisError.

Returns:
Nothing.
Parameters:
sFilename - Destination file name.
sVarName - Name of matrix.
sComment - Comment in the LaTeX file.
fWriteAsTable - If true the matrix is formatted as a table.
sNumFmt - printf c-stype format of numbers, e.g. "%.2f".
sBracketType - Either "[" or "(".
fAppend - If true 'sFilename' is append with this matrix.
Author:
Mikkel B. Stegmann
Version:
4-5-2000

oDIVAMatrixExport void ToMatlab( const CDString& sFilename, const CDString& sName, const CDString& sComment, bool fAppend) const

Writes the matrix to disk in MatLab (.m) format. To read the matrix into MatLab write e.g. 'my_matrix.m' at the MatLab prompt.

Notice that this should be used for storage a (really) large matrices, due to the computational and i/o overhead induced by the simple MatLab text format.

Also, remember that MatLab can't read (.m) files with lines longer than 4096 bytes.

If no communication with MatLab is needed, but merely to/from disk functionality within a DIVA program, it is suggested to use the fast binary i/o methods ToFile() and FromFile().

Returns:
Nothing.
Parameters:
sFilename - Output file name. Should have the extension '.m'.
sName - Name of destination matlab variable.
sComment - Optional comment inside the file.
fAppend - If true, the vector is appended to the file 'sFilename'.
Author:
Henrik Aanęs
Version:
14-7-1999

oDIVAMatrixExport CDString ToString() const

Returns a string representing the matrix.

Returns:
A string.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void TriL( CDMatrix &matrix, const int K ) const

Extracts the elements on and below the K-th diagonal. K = 0 is the main diagonal, K > 0 is above the main diagonal and K < 0 is below the main diagonal.

Returns:
Nothing.
Author:
Lars Pedersen
Version:
6-12-2000

oDIVAMatrixExport void TriU( CDMatrix &matrix, const int K ) const

Extracts the elements on and above the K-th diagonal. K = 0 is the main diagonal, K > 0 is above the main diagonal and K < 0 is below the main diagonal.

Returns:
Nothing.
Author:
Lars Pedersen
Version:
5-12-2000

oDIVAMatrixExport double Var() const

Calc the variance of the matrix.

Returns:
The variance value.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport void VarCol(CDVector& vVar) const

Calc the variance of each column into a vector. The vector will be resized if it doesn't have the right length.

Returns:
Nothing.
Parameters:
vVar - Output vector.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrix.h DIVAMatrixExport CDMatrix& operator=(const CVisDMatrix &mat)

Assignment operator (CVisDMatrix).

Returns:
This.
Parameters:
mat - Input matrix.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport CDMatrix& operator=(const CDMatrix &mat)

Assignment operator (CDMatrix).

Returns:
This.
Parameters:
mat - Input matrix.
Author:
Rune Fisker
Version:
3-14-2001

oDIVAMatrixExport CDMatrix& operator=(double value)

Assignment operator (double). Set all values equal to 'value'.

Returns:
This.
Parameters:
value - Input double.
Author:
Rune Fisker
Version:
3-14-2001


This class has no child classes.
Author:
Rune Fisker, Mikkel B. Stegmann, Henrik Aanęs, Lars Pedersen et al.
Version:
2-5-2001
See Also:
CDVector


Back DIVA Reference Manual The DIVA-Site