How to reference to a struct field with char array?
조회 수: 44 (최근 30일)
이전 댓글 표시
I have following problem and can't seem to find a solution, probably because I'm lacking some basic understanding.
I have a multilayer struct array (not sure if the term 'multilayer is used correctly here) and I am trying to reference to one of the 'sub'field.
The structure of the variable is as follows:
TestUnits [1x1 struct]: contains A and B
- A [1x1 struct]: contains ABA, ABB, ABC ...... so on
- >> ABA [1x5 struct]: contains following structure aas shown in the image below)
- >> >> contains 5 [1x1] struct
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1322910/image.png)
- >> ABB [1x5 struct]
- >> ABC [1x5 struct]
- B [1x1 struct] (same structure as A)
When I manually evaluate this statement:
>>TestUnits.A.ABA(1).Values
I get an answer listing the content of the struct array.
But when I try to define a char variable and then use it to access the content of the struct array i get an error.
>>man={'ABA(1)'}
>> TestUnits.A.(man).Values
Argument to dynamic structure reference must evaluate to a valid field name.
and when i try this , i get the following
>> TestUnits.A.(man{1}).Values
Reference to non-existent field 'ABA(1)'.
By the way, there no such field as ABA(1). ABS is a 1x5 struct as explained above. I am trying to access the contents of one of the 5 1x1 structs.
How do i do it? Can i not use the referencing method mentioned above? I hope I explained my problem good enough.
댓글 수: 0
채택된 답변
추가 답변 (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!