Borrar filtros
Borrar filtros

Subscripted assignment dimension mismatch in structure.

2 visualizaciones (últimos 30 días)
purdueaviator
purdueaviator el 23 de Jul. de 2016
Respondida: Div Tiwari el 8 de Ag. de 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 comentario
Geoff Hayes
Geoff Hayes el 23 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Div Tiwari
Div Tiwari el 8 de Ag. de 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';

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by