[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
structures in cell arrays
From: |
John W. Eaton |
Subject: |
structures in cell arrays |
Date: |
Wed, 24 Sep 2003 12:10:28 -0500 |
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/msg00012.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
-------------------------------------------------------------