help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: structures in cell arrays


From: Paul Griffiths
Subject: Re: structures in cell arrays
Date: Fri, 26 Sep 2003 13:04:33 -0500

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'

After some experimenting, I think the problem occurs
when Octave tries to load an empty cell of a cell array. If the empty cells
of the cell array, X, are set to the empty matrix, [], then I can load the
mat file.

It is not clear to me whether Octave actually distinguishes between an
empty cell and a cell containing an empty matrix. In Matlab, the
distinction seems to be unimportant other than the larger amount of
storage space required for non-empty cells in workspace memory and on disk.
Anyway, it would be nice if we could load cell arrays containing empty
cells. Is there a patch or any directions on updating load-save.cc? 

Regards,
Paul Griffiths

On Wed, 24 Sep 2003 12:10:28 -0500 "John W. Eaton" <address@hidden> wrote:

> On 24-Sep-2003, Paul Griffiths <address@hidden> wrote:
> 
> | I have seen that a cell array element can be a structure. (See:
> |
> http://www.octave.org/octave-lists/archive/octave-maintainers.2002/msg000
> 12.html)
> | 
> | The example given is:
> | octave:1> X{2,2}.bar(2).foo(2:3,2:3) = rand(2)
> | 
> | But I get the following error message when I try this statement:
> | error: matrix cannot be indexed with .
> | error: assignment failed, or no method for `<unknown type> = matrix'
> | error: evaluating assignment expression near line 1, column 28
> | octave:1> 
> | 
> | I have tried this on versions 2.1.44 and 2.1.50. I don't even need
> | structure arrays. It would be sufficient if I could assign X{2,2}.a =
> 1. 
> 
> | Is there a patch? I also wish to load and save cell arrays with
> structures.
> | If need be, I would consider contributing code to get this to work.
> 
> I think load/save should work if you use the HDF5 or Matlab formats.
> 
> Please try the following patch to fix the indexing problem.
> 
> Thanks,
> 
> jwe
> 
> 
> src/ChangeLog
> 
> 2003-09-24  John W. Eaton  <address@hidden>
> 
>         * ov-cell.cc (octave_cell::subsasgn): Also attempt empty
>         conversion after extracting single element from cell array to
>         allow things like x{i}.elt = rhs to work.
> 
> 
> Index: src/ov-cell.cc
> ===================================================================
> RCS file: /usr/local/cvsroot/octave/src/ov-cell.cc,v
> retrieving revision 1.23
> diff -u -r1.23 ov-cell.cc
> --- src/ov-cell.cc        19 Sep 2003 21:41:21 -0000        1.23
> +++ src/ov-cell.cc        24 Sep 2003 17:09:02 -0000
> @@ -158,7 +158,11 @@
>  
>                      tmp.make_unique ();
>  
> -                    t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs);
> +                    if (! tmp.is_defined () || tmp.is_empty ())
> +                      tmp = octave_value::empty_conv (type.substr (1), rhs);
> +
> +                    if (! error_state)
> +                      t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs);
>                    }
>                }
>            }
> 
> 
> 




-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]