How to reference to a struct field with char array?
26 ビュー (過去 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

- >> 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!