Subscripted assignment dimension mismatch in structure.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2016-7-23
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.
回答(1 个)
Div Tiwari
2016-8-8
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';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!