Menu

Appending to Matfiles

jlam9012
2014-03-18
2019-09-19
  • jlam9012

    jlam9012 - 2014-03-18

    Hi, first off, thank you for creating this project. My question is whether or not it is possible to append to an existing matfile. If it is, a brief example would really help. Thank you!

     
    • Tobias

      Tobias - 2014-03-19

      Appending to an existing matfile is not possible with the current version of csmatio. However you can:

      I) read the content of a mat file,
      II) append some data to the content that was read,
      III) finally write the new (original+appended) content to a new file.

      Here is an example:

      // create a reader for the input file and read the file
      MatFileReader mfr = new MatFileReader("appendInput.mat");
      
      // create a reference to complete matlab variables list
      List<MLArray> mlList = mfr.Data;
      
      // append some data to the matlab variables list
      double[][] doubleMatrix2by2 = new double[2][];
      doubleMatrix2by2[0] = new double[] { 3, 4 };
      doubleMatrix2by2[1] = new double[] { 5, 6 };
      mlList.Add(new MLDouble("DoubleMatrix2by2", doubleMatrix2by2));
      
      string textMessage = "append data to mat file";
      mlList.Add(new MLChar("TextMessage", textMessage));
      
      // create a writer for the output file and write the file
      MatFileWriter mfw = new MatFileWriter("appendOutput.mat", mlList, true);        
      
       

      Last edit: Tobias 2014-03-19
      • jlam9012

        jlam9012 - 2014-03-26

        Thank you for the example.

         

        Last edit: jlam9012 2014-03-26
  • Ben Human

    Ben Human - 2016-12-16

    Hi Tobias,
    I was wondering whether since this post there has been any update on appending to MAT files. I have a problem that I am trying to write about 200MB of data to a MAT file in C# but seems to crash at the MatFileWriter so it seems to be too big. Im not sure that your advice above would solve the problem because eventually you would be writing the full 200MB to the file?
    Any help would be much appreciated, Thanks. Ben

     
    • Tobias

      Tobias - 2016-12-17

      Hi Ben, there was a similar discussion two years ago, see Ticket [#4]. I assume that things haven't changed since them. Could you give a detailled bug report?

       

      Related

      Tickets: #4


      Last edit: Tobias 2016-12-17
  • Anuj Dubey

    Anuj Dubey - 2019-09-19

    Hi Tobias,
    Was wondering if the support for appending data to an already existing mat file is available now?
    Thanks.

     
    • Tobias

      Tobias - 2019-09-19

      In short: No it's not. The way the library works is "read only" from existing mat files. Writing to existing mat files would require a different approach. I'm sorry, but at the moment there are no plans for further development of the library.

       
  • Anuj Dubey

    Anuj Dubey - 2019-09-19

    I see. Thanks for the info.

     

Log in to post a comment.