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


Apr 8, 2013 at 5:57 PM
I'm trying to use ReadMatrix(stream) and keep getting a null object reference:
        string strData = "3 4 5 6";
        byte[] data = Encoding.ASCII.GetBytes(strData);
        Stream dataStream = new MemoryStream(data, 0, data.Length);
        Matrix<Double> P = mat.ReadMatrix(dataStream);
Can someone suggest how to convert a string to matrix with the ReadMatrix method? Also, how does the method know to make the string above a 1x4 matrix or 2x2?
Apr 8, 2013 at 6:15 PM

Where does ReadMatrix(stream) come from, i.e. what is the mat object?
Could you add a stack trace of the exception, ideally with line numbers?

Apr 8, 2013 at 8:05 PM

I left off a key line (which should precede the code shown above):
        DelimitedReader<Matrix<Double>, Double> mat = new DelimitedReader<Matrix<Double>, Double>();
DelimitedReader is in the: MathNet.Numerics.LinearAlgebra.Double.IO namespace:

Apr 9, 2013 at 4:33 PM
Thanks. Could you also copy the stack trace of the exception here?

Apr 9, 2013 at 4:44 PM
Thanks. I'm building an app and I want to let user type a matrix into a textbox and then use ReadMatrix to convert it to a Matrix. Of course I can parse it myself, but thought I'd try the ReadMatrix method, which requires a Stream.

This is the line that threw the exception:

Line 93: Matrix<Double> P = mat.ReadMatrix(dataStream);// DisplayMatrix("Matrix 5, P=", P, formatProvider);

And, the stack trace:

[NullReferenceException: Object reference not set to an instance of an object.]
MathNet.Numerics.LinearAlgebra.IO.DelimitedReader2.DoReadMatrix(Stream stream) in c:\TeamCity\buildAgent\work\d4ecde2945c804d6\src\Numerics.IO\LinearAlgebra\IO\DelimitedReader.cs:269
2.ReadMatrix(Stream stream) in c:\TeamCity\buildAgent\work\d4ecde2945c804d6\src\Numerics.IO\LinearAlgebra\IO\MatrixReader.cs:77
MatrixApp._default.Page_Load(Object sender, EventArgs e) in E:\Data-Classes\CS 3340 - Web Programming\Topics\06_WebServices&Components\assignments\Regression\Sp13\MatrixApp\MatrixApp\default.aspx.cs:93
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Apr 9, 2013 at 4:52 PM
Thanks, that helps to pinpoint the problem.

Could you retry but this time with a concrete matrix type in the reader?
var mat = new DelimitedReader<DenseMatrix, double>();
(DenseMatrix from the MathNet.Numerics.LinearAlgebra.Double namespace)

Marked as answer by cdrnet on 10/3/2013 at 3:39 PM
Apr 9, 2013 at 5:07 PM
Works great! Thanks so much---dave