BioloMICS logo
×
BioloMICS menu

Matrix manipulations

 
This is a little example showing how to manipulate a matrix.
 
'     create a similarity matrix
Dim SimMx As New XMatrix(10, 10)
For r As Integer = 0 To 9     '     row loop
     SimMx(r)(r) = 1.0     '     diagonal
     For c As Integer = r + 1 To 9      '     column loop
          SimMx(r)(c) = (r + 1) * (c + 1) / 100
     Next
Next
'     keep top values (where c > r)
SimMx.SymetricKeepTop()
'     build a string with the matrix values
Dim MxStr As String = SimMx.ToString
 
'     Create a distance matrix, the 1-complement of SimMx
Dim DistMx As New XMatrix(SimMx)
DistMx.Complement()
'     Compute the correlation matrix between the Similarity matrix and its counterpart: the distance matrix
Dim Cor As Double = SimMx.Correlation(DistMx)     '     must be -1.0
Cor = SimMx.Correlation(SimMx)     '     where the correlation with itself = 1.0
 
 
KEEP