help-octave
[Top][All Lists]
Advanced

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

Re: cell2struct error


From: Jaroslav Hajek
Subject: Re: cell2struct error
Date: Tue, 18 Aug 2009 10:49:18 +0200

On Tue, Aug 18, 2009 at 10:30 AM, Michael
Grossbach<address@hidden> wrote:
> Adding fields to a struct fails when the struct has been assigned before
> using cell2struct:
>
>
> keys = {"one"; "two"};
> values = {1, 3; 2, 4};
> s = cell2struct(values, keys, 2);
> s.three = [5;6]
> error: invalid structure assignment
> error: assignment to structure element failed
> error: assignment failed, or no method for `struct = matrix'
> error: evaluating assignment expression near line 23, column 9


Since at this point s is a 2x1 struct array,
s.three is a cs-list expression; you can't assign a matrix into it
(it's not even a valid reference unless enclosed in brackets). either
do
s(1).three = 5;
s(2).three = 6;
or
[s.three] = deal (5, 6);
or
[s.three] = num2cell ([5;6]){:};
or whatever is suitable, but you must produce a cs-list if you want to
assign to one.



>
> This is Octave 3.0.1 on Debian Lenny. Has this been fixed in more recent
> versions? Or am I doing something wrong?
>

Definitely, I recommend you upgrade; a lot has been fixed in this area
since 3.0.1.


-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

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