Search code examples
octavecell-array

Best Function and File Format for Saving and Retrieving a Cell Array from a File in Octave


What would be the most performant function (scanf, fscanf, load, textread) and file format (dat, mat, txt, csv) combination to read a file in Octave that contains a cell array?

And which function should I use to store the cell array in that file, in the most read-performant format defined above?

Note that performance is more important for the read operation, since that’s the one I’ll be using the most. But having a performant function to write the files would be desirable too.


Solution

  • octave:1> MyCell = {'a', 'cell', 'with', 5, 'elements'};
    octave:2> save -binary myworkspace.dat MyCell
    octave:3> clear
    octave:4> load -binary myworkspace.dat
    octave:5> MyCell 
    MyCell = 
    {
      [1,1] = a
      [1,2] = cell
      [1,3] = with
      [1,4] =  5
      [1,5] = elements
    }
    

    or

    octave:6> S = load ('-binary', 'myworkspace.dat');
    octave:7> S.MyCell
    ans = 
    {
      [1,1] = a
      [1,2] = cell
      [1,3] = with
      [1,4] =  5
      [1,5] = elements
    }