This project has moved and is read-only. For the latest updates, please go here.

Matlab Reader in VB.net?

May 26, 2014 at 9:07 PM
I am struggling to understand how to create a MatlabMatrixReader in visual basic.

Here is what I've tried:

Dim Matrix_A As DenseMatrix
    Dim MatrixReader_A As Data.Matlab.MatlabMatrixReader(__Of DenseMatrix__)
    MatrixReader_A.ReadMatrix("C:\pathtofile\something.mat")
I don't know what should go into the argument (in bold) when declaring the matrix reader.
I get the following compile errors for the argument of DenseMatrix:

Error 1 Type argument 'MathNet.Numerics.LinearAlgebra.Double.DenseMatrix' does not inherit from or implement the constraint type 'System.IEquatable(Of MathNet.Numerics.LinearAlgebra.Double.DenseMatrix)'. C:\Users\Vardavis\Documents\Visual Studio 2012\Projects\Seizure Recognition\Seizure Recognition\Form1.vb 21 57 Seizure Recognition

Error 2 Type argument 'MathNet.Numerics.LinearAlgebra.Double.DenseMatrix' does not satisfy the 'Structure' constraint for type parameter 'TDataType'. C:\Users\Vardavis\Documents\Visual Studio 2012\Projects\Seizure Recognition\Seizure Recognition\Form1.vb 21 57 Seizure Recognition

Furthermore how do I populate Matrix_A with the results from the matrix reader?
May 26, 2014 at 9:30 PM
Edited May 26, 2014 at 9:36 PM
The MATLAB reader design is indeed a bit awkward, hopefully we can fix that for the v3 release. The type argument is the data type of the matrix values, i.e. Double, Single, Complex or Complex32. In essence, you have to create an instance with the path to the MAT file as argument. Then you can read one or all of the matrices using its read functions.

Example in C# (sorry, I'm not fluent in VB.net anymore):
var dmr = new MatlabMatrixReader<double>("./data/Matlab/A.mat");
var matrix = dmr.ReadMatrix();
More examples in the unit tests.

Thanks,
Christoph
Marked as answer by MatthewRyanDavis on 5/26/2014 at 1:53 PM
May 26, 2014 at 9:51 PM
Edited May 27, 2014 at 2:50 AM
Thank you Christoph!
That lead me to a working solution.
Here it is for VB.net:
    Dim reader As New Data.Matlab.MatlabMatrixReader(Of Double)("C:\Seizure\testmatrix.mat")
    Dim Matrix_A As DenseMatrix = reader.ReadMatrix