how to implement structfun using 2 variables
古いコメントを表示
Hi all,
Is it possible to have a code which is similar to
S.value1.x = 1;
S.value2.x = 10;
S.value3.x = 17;
S1.value1.x = 12;
S1.value2.x = 11;
S1.value3.x = 13;
S2.value1.x = 142;
S2.value2.x = 11;
S2.value3.x = 113;
output1 = structfun(@(In, val)In.val.x,S,value1)
output2 = structfun(@(In, val)In.val.x,S1,value1)
Output:
output1 = 1
output2 = 12
Here I need to changing parameter.
Thanks,
Raghunandan V
1 件のコメント
Stephen23
2019 年 6 月 4 日
This seems to be closely related, and has some relevant answers:
採用された回答
その他の回答 (1 件)
Jan
2019 年 6 月 4 日
This seems to be much easier:
field = 'value1';
output1 = S.(field).x
output1 = S1.(field).x
structfun iterates over the fields of a struct. So it is not clear why you want to use it to get the values of a nested substruct.
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!