필터 지우기
필터 지우기

Subscripted assignment dimension mismatch in structure.

조회 수: 2 (최근 30일)
purdueaviator
purdueaviator 2016년 7월 23일
답변: Div Tiwari 2016년 8월 8일
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
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
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';

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by