﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Bluebit Software Support Forum / Technical Support and Help / .NET Matrix Library  / Saving a matrix to a file and reading it back / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>Bluebit Software Support Forum</description><link>http://www.bluebit.gr/forum/</link><webMaster>support@bluebit.gr</webMaster><lastBuildDate>Thu, 17 May 2012 06:44:46 GMT</lastBuildDate><ttl>20</ttl><item><title /><link>http://www.bluebit.gr/forum/Topic63-3-1.aspx</link><description>guille, here is the same code in vb.net[code]    Private Sub SaveAndLoadDemo()        'Create a matrix object        Dim myMatrix = New Matrix(4, 4)        myMatrix.FillRandom()        'Print the matrix                    Console.WriteLine(myMatrix)        'Save the matrix to an xml file        SaveXML(myMatrix, "C:\\MyMatrix.xml")        'Open the saved matrix into another variable                    Dim mySavedMatrix As Matrix = LoadXML("C:\\MyMatrix.xml")        Console.WriteLine(mySavedMatrix)    End Sub    'Using XML Serialization to save a matrix    Private Sub SaveXML(ByVal matrix As Matrix, ByVal filePath As String)        'Open a file stream         Dim fs As System.IO.FileStream = New System.IO.FileStream(filePath, System.IO.FileMode.Create)        'Create a xml Serializer object        Dim xmlSer As System.Xml.Serialization.XmlSerializer = New System.Xml.Serialization.XmlSerializer(GetType(Bluebit.MatrixLibrary.Matrix))        'Save the matrix        xmlSer.Serialize(fs, matrix)        'Close the file stream        fs.Close()    End Sub    'Load a matrix from an XML file    Private Function LoadXML(ByVal filePath As String) As Matrix            'Open the XML file        Dim FS As System.IO.FileStream = New System.IO.FileStream(filePath, System.IO.FileMode.Open)        'First create a xml Serializer objecT        Dim xmlSer As System.Xml.Serialization.XmlSerializer = New System.Xml.Serialization.XmlSerializer(GetType(Bluebit.MatrixLibrary.Matrix))        'Deserialize the Matrix object        Dim matrix As Matrix = CType(xmlSer.Deserialize(FS), Bluebit.MatrixLibrary.Matrix)        'Close the file stream        FS.Close()        'Return the matrix object        Return matrix    End Function    'Using Binary Serialization to save a matrix    Private Sub SaveBinary(ByVal matrix As Matrix, ByVal filePath As String)        'Open a file stream         Dim fs As System.IO.FileStream = New System.IO.FileStream(filePath, System.IO.FileMode.Create)        'Initialize a BinnaryFormatter object        Dim binFor As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter        'Save the matrix        binFor.Serialize(fs, matrix)        'Close the file stream        fs.Close()    End Sub    'Load a matrix from a binary file    Private Function LoadBinary(ByVal filePath As String) As Matrix        'Open a file stream        Dim fs As System.IO.FileStream = New System.IO.FileStream(filePath, System.IO.FileMode.Open)        'Initialize a BinnaryFormatter object        Dim binFor As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter        'Deserialize the Matrix object        Dim matrix As Matrix = CType(binFor.Deserialize(fs), Bluebit.MatrixLibrary.Matrix)        'Close the file stream        fs.Close()        'Return the matrix object        Return matrix    End Function[/code]</description><pubDate>Mon, 25 Jul 2005 01:26:21 GMT</pubDate><dc:creator>Trifon</dc:creator></item><item><title /><link>http://www.bluebit.gr/forum/Topic63-3-1.aspx</link><description>SaveXML(myMatrix, "C:\\MyMatrix.xml");What is the same code to save matrix but in vb.net? </description><pubDate>Thu, 21 Jul 2005 12:03:25 GMT</pubDate><dc:creator>guille</dc:creator></item><item><title /><link>http://www.bluebit.gr/forum/Topic63-3-1.aspx</link><description>HiIt can be done very easily using either XML or Binary Serialization. Please review the following code example:[code]       private void SaveAndLoadDemo()        {            // Create a matrix object            Matrix myMatrix = new Matrix(4, 4);            myMatrix.FillRandom();            // Print the matrix                        Console.WriteLine(myMatrix);                        // Save the matrix to an xml file            SaveXML(myMatrix, "C:\\MyMatrix.xml");                                    // Open the saved matrix into another variable                        Matrix mySavedMatrix = LoadXML("C:\\MyMatrix.xml");            Console.WriteLine(mySavedMatrix);         }                                                // Using XML Serialization to save a matrix        private void SaveXML(Matrix matrix, string filePath)        {                        //Open a file stream             System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create) ;                                    // Create a xml Serializer object            System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(typeof(Bluebit.MatrixLibrary.Matrix));                                  //Save the matrix            xmlSer.Serialize(fs, matrix);                        // Close the file stream            fs.Close();                                                                  }                // Load a matrix from an XML file        private Matrix LoadXML(string filePath)        {            //Open the XML file            System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open) ;                                       // First create a xml Serializer object            System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(typeof(Matrix));                        // Deserialize the Matrix object            Matrix matrix = (Matrix) xmlSer.Deserialize(fs);                        // Close the file stream            fs.Close();                        // Return the matrix object            return matrix;        }                // Using Binary Serialization to save a matrix        private void SaveBinary(Matrix matrix, string filePath)        {            //Open a file stream             System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create) ;                                    // Initialize a BinnaryFormatter object            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binFor = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();                        //Save the matrix            binFor.Serialize(fs, matrix);                        // Close the file stream            fs.Close();           }                // Load a matrix from a binary file        private Matrix LoadBinary(string filePath)        {            //Open a file stream             System.IO.FileStream fs = new System.IO.FileStream(filePath,System.IO.FileMode.Open) ;                                       // Initialize a BinnaryFormatter object            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binFor = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();                       // Deserialize the Matrix object            Matrix matrix = (Matrix) binFor.Deserialize(fs);                         // Close the file stream            fs.Close();                        // Return the matrix object            return matrix;        }[/code]</description><pubDate>Fri, 17 Jun 2005 00:29:15 GMT</pubDate><dc:creator>Trifon</dc:creator></item><item><title>Saving a matrix to a file and reading it back</title><link>http://www.bluebit.gr/forum/Topic63-3-1.aspx</link><description>Hello,I’m using the .NET Matrix Library. I have one question, and I can’t find the answer.Is there a way to store a matrix on disk, and read it again from the disc back to the application? I know that I can use the .ToString method to save the matrix in a text file, but how can I then read the matrix back to my application? I want to save the matrix on disc because I don’t want to create the matrix always from scratch.Thank you for your answer.</description><pubDate>Fri, 17 Jun 2005 00:21:22 GMT</pubDate><dc:creator>anonymous</dc:creator></item></channel></rss>
