How can I refer to all fields (of a particular level) within a structure?
3 ビュー (過去 30 日間)
古いコメントを表示
Example: I have a struct such as this (simplified): Students.Gender.Height
I want to refer to and operate upon all fields regardless of gender. So, Students.Boy.6feet or Students.Girl.6feet would both be affected by the operation. Not a great example, but I hope I am conveying the need here. Is there a wildcard or () or {} type of way to index or refer to all fields of the "gender" level?
0 件のコメント
採用された回答
James Tursa
2018 年 7 月 5 日
What "works" is probably going to depend on what is contained in the sub-fields and what you intend to do with this data downstream in your code. E.g., for your simplistic example if you wanted to extract the data (assuming the Height was scalar):
result = cellfun(@(x)Students.(x).Height,fieldnames(Students))
That would give you a result variable that you could use downstream.
Maybe you could give us more detail on the fields of your structure, and what operations you intend.
その他の回答 (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!