From: Walter Roberson on 8 Jul 2010 11:07 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: Jay WONG on 8 Jul 2010 11:30 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i14p7r$ilt$1(a)fred.mathworks.com>... > 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 hi Jan, This is what I intend to do: 1)I would like to create a 3D struct array of size (17x16X91), empty field in the first place. 2)Then, I would like to assign my complex struct arrays of size(1X1) to each unit in that 3D array. How do I accomplish this? thank you, Jay
From: Jan Simon on 8 Jul 2010 11:56 Dear Jay, > This is what I intend to do: > 1)I would like to create a 3D struct array of size (17x16X91), empty field in the first place. > 2)Then, I would like to assign my complex struct arrays of size(1X1) to each unit in that 3D array. How do I accomplish this? Simply use another language than Matlab. Not kidding. You have to create the struct array with the correct fields initially. Perhaps using a cell is better in your case, because elements of a cell are allowed to be as different as you wish. Kind regards, Jan
From: Jay WONG on 8 Jul 2010 15:24 Dear Jan, I modified a bit. Now I initiated the field first and would like to concatenate two structs into one struct, but still failed. Could you explain why? ====================================== CUBE_DATA(17,16,91)=struct('C1', TRADE_ID(2,1),'C2',INDUSTRY_LABEL(2,1),'C3', TENOR(2,1),'C4', TIME_TO_MATURITY(2,1),'C5',TYPE(2,1),'C6',SERIES(2,1),'C7', NOTIONAL(2,1),'C8', MATCHED_STATUS(2,1),'C9', SUBMITTED_STATUS(2,1)); TEMP=struct('C1', TRADE_ID(2,1),'C2',INDUSTRY_LABEL(2,1),'C3', TENOR(2,1),'C4', TIME_TO_MATURITY(2,1),'C5',TYPE(2,1),'C6',SERIES(2,1),'C7', NOTIONAL(2,1),'C8', MATCHED_STATUS(2,1),'C9', SUBMITTED_STATUS(2,1)); CUBE_DATA(17,16,91)=('F1',TEMP,'F2',CUBE_DATA(17,16,91)); ====================================== "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i14sek$j9r$1(a)fred.mathworks.com>... > Dear Jay, > > > This is what I intend to do: > > 1)I would like to create a 3D struct array of size (17x16X91), empty field in the first place. > > 2)Then, I would like to assign my complex struct arrays of size(1X1) to each unit in that 3D array. How do I accomplish this? > > Simply use another language than Matlab. Not kidding. You have to create the struct array with the correct fields initially. > Perhaps using a cell is better in your case, because elements of a cell are allowed to be as different as you wish. > > Kind regards, Jan
From: Walter Roberson on 8 Jul 2010 15:35 Jay WONG wrote: > I modified a bit. Now I initiated the field first and would like to > concatenate two structs into one struct, but still failed. > > Could you explain why? > CUBE_DATA(17,16,91)=('F1',TEMP,'F2',CUBE_DATA(17,16,91)); 'F1',TEMP,'F2', is not a structure and so cannot be concatenated with the structure CUBE_DATA(17,16,91) . If you were to code CUBE_DATA(17,16,91)=struct('F1',TEMP,'F2',CUBE_DATA(17,16,91)); then you would be attempting to change the structure fields for the single structure array element CUBE_DATA(17,16,91) and that is not permitted. As I wrote in my earlier response, "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."
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: plotting multiple objects on the same figure Next: Spectrum Sharing |