Filter löschen
Filter löschen

Subscripted assignment dimension mismatch in structure.

2 Ansichten (letzte 30 Tage)
purdueaviator
purdueaviator am 23 Jul. 2016
Beantwortet: Div Tiwari am 8 Aug. 2016
I am trying to create a structure with a lot of information and multiple layers.
Level(10).Sublevel(5).XXXXX = 'test' works just fine
However, when I try to add another sublevel such as
Level(10).Sublevel(5).Subsublevel(15).XXXXX = 'test'
I get the Subscripted assignment dimension mismatch error.
Is this a MATLAB limitation or am I doing something wrong?
  1 Kommentar
Geoff Hayes
Geoff Hayes am 23 Jul. 2016
At what point do you call the second line of code? If I execute the following two lines in succession
Level(10).Sublevel(5).XXXXX = 'test';
Level(10).Sublevel(5).Subsublevel(15).XXXXX = 'test';
then I don't observe any errors. Please provide more details.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Div Tiwari
Div Tiwari am 8 Aug. 2016
Was the first assignment Level(10).Sublevel(5).Subsublevel = 'test'? That makes 'Level(10).Sublevel(5).Subsublevel' a 'char' vector of length 4. As a result, indexing into 'Subsublevel' with an index greater than 4 gives a 'Field assignment to a non-structure array object' error. Using an index of 4 or less will result in a size mismatch error.
To get around this, you may reassign 'Subsublevel' as a struct before the second assignment, as follows:
>> Level(10).Sublevel(5).Subsublevel = 'test';
>> Level(10).Sublevel(5).Subsublevel = struct;
>> Level(10).Sublevel(5).Subsublevel(15).XXXXX = 'test';

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by