From: Jay WONG on 8 Jul 2010 10:53 hi, I created the following code but failed with this message "Subscripted assignment between dissimilar structures." Please advise what went wrong Thank you ============= TYPE=zeros(100,1); OK=zeros(100,1); CUBE_DATA(17, 16, 19)=struct(); S=struct('C1',TYPE,'C2',OK); CUBE_DATA(1, 1, 1)=S; =====================
From: Andy on 8 Jul 2010 11:00 "Jay WONG" <dcba7777(a)hotmail.com> wrote in message <i14oog$gkv$1(a)fred.mathworks.com>... > hi, > I created the following code but failed with this message "Subscripted assignment between dissimilar structures." > Please advise what went wrong > Thank you > > > > ============= > TYPE=zeros(100,1); > OK=zeros(100,1); > CUBE_DATA(17, 16, 19)=struct(); > > S=struct('C1',TYPE,'C2',OK); > CUBE_DATA(1, 1, 1)=S; > > ===================== Since you haven't provided the full code or the full error message, we cannot be certain what the problem is. But my guess is that this is the problematic line: CUBE_DATA(17, 16, 19)=struct(); Hint: Is CUBE_DATA an array of doubles?
From: Jan Simon on 8 Jul 2010 11:01 Dear Jay, > I created the following code but failed with this message "Subscripted assignment between dissimilar structures." > TYPE=zeros(100,1); > OK=zeros(100,1); > CUBE_DATA(17, 16, 19)=struct(); Now CUBE_DATA is a [17 x 18 x 19] struct array with *no* fields. > S=struct('C1',TYPE,'C2',OK); > CUBE_DATA(1, 1, 1)=S; Now you want to set the first element of the struct array to a struct *with* some fields. That is simply not possible. You can pre-allocate CUBE_DATA e.g. by defining the last element at first or using STRUCT with cells as input data. Good luck, Jan
From: Walter Roberson on 8 Jul 2010 11:04 Jay WONG wrote: > hi, I created the following code but failed with this message > "Subscripted assignment between dissimilar structures." > Please advise what went wrong > Thank you > > > > ============= > TYPE=zeros(100,1); > OK=zeros(100,1); > CUBE_DATA(17, 16, 19)=struct(); That initializes CUBE_DATA to be an array of structures with no fields. > S=struct('C1',TYPE,'C2',OK); > CUBE_DATA(1, 1, 1)=S; That tries to assign a structure with fields into the array of structures with no fields. When you assign a complete structure into an array of structures, then the structure being assigned from must have the same fields in _exactly_ the same order as the structure being assigned into. This differs from assigning to a _field_ of a structure: if you assign to a _field_ of a structure, then the field will automatically be created if it does not already exist. I suggest you use CUBE_DATA(17, 16, 19) = struct('C1',TYPE,'C2',OK); This will initialize the structure fields for all of the array members; if your code had worked, it would have only initialized the structure fields for the _first_ array member.
From: Walter Roberson on 8 Jul 2010 11:06
Jay WONG wrote: > hi, I created the following code but failed with this message > "Subscripted assignment between dissimilar structures." > Please advise what went wrong > Thank you > > > > ============= > TYPE=zeros(100,1); > OK=zeros(100,1); > CUBE_DATA(17, 16, 19)=struct(); That initializes CUBE_DATA to be an array of structures with no fields. > S=struct('C1',TYPE,'C2',OK); > CUBE_DATA(1, 1, 1)=S; That tries to assign a structure with fields into the array of structures with no fields. When you assign a complete structure into an array of structures, then the structure being assigned from must have the same fields in _exactly_ the same order as the structure being assigned into. This differs from assigning to a _field_ of a structure: if you assign to a _field_ of a structure, then the field will automatically be created if it does not already exist. I suggest you use CUBE_DATA(17, 16, 19) = struct('C1',TYPE,'C2',OK); This will initialize the structure fields for all of the array members; if your code had worked, it would have only initialized the structure fields for the _first_ array member. |