From help-octave-request at bevo dot che dot wisc dot edu Fri Sep 26 15:32:31 2003 Subject: Re: structures in cell arrays From: "John W. Eaton" To: Paul Griffiths Cc: help-octave at bevo dot che dot wisc dot edu Date: Fri, 26 Sep 2003 15:28:21 -0500 On 26-Sep-2003, Paul Griffiths wrote: | Hi, | Thanks for the patch - it did fix the indexing problem (although for some | reason I could not apply the patch and had to edit load-save.cc manually.) | | I found that not all cell arrays saved in MATLAB can be loaded in Octave. | The example given before, X{2,2}.foo(2).bar(2:3,2:3) = rand(2), when saved | in MATLAB, cannot be loaded into Octave. Even if we consider a simpler | case, X{2,2} = 1; | | >> X{2,2} = 1 | | X = | | [] [] | [] [1] | | >> save x.mat X | | And then we try to load this file in Octave, | | octave-2.1.50:3> load x.mat | error: load: invalid array flags subelement | error: load: trouble reading binary file `x.mat' | error: load: reading cell data for `' | error: load: trouble reading binary file `x.mat' Please try the following patch. Thanks, jwe 2003-09-26 John W. Eaton * load-save.cc (read_mat5_binary_element): Return early if the miMATRIX element has length zero. Index: src/load-save.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/load-save.cc,v retrieving revision 1.173 diff -u -r1.173 load-save.cc --- src/load-save.cc 19 Sep 2003 21:41:21 -0000 1.173 +++ src/load-save.cc 26 Sep 2003 20:27:36 -0000 at @ -2600,6 +2600,8 @@ TWO_BYTE_INT number; number = *(TWO_BYTE_INT *)"\x00\x01"; + global = false; + // MAT files always use IEEE floating point if ((number == 1) ^ swap) flt_fmt = oct_mach_info::ieee_big_endian; at @ -2615,6 +2617,13 @@ error ("load: invalid element type"); goto early_read_error; } + + if (element_length == 0) + { + tc = Matrix (); + return retval; + } + pos = is.tellg (); // array flags subelement ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------