How to (nicely) copy a structure array field into another
61 ビュー (過去 30 日間)
古いコメントを表示
Based on several questions in this forum, the following piece of code works. But I wonder if there is a more 'elegant' or 'neat' way in Matlab ('matlabish', 'matlabonic'...?)
% S is a given structure (I definetely can't modify that)
S(1).name = [];
S(2).name = [];
% Nicely stored input data (I could parse this differently, but this is not the point)
data(1).name = 'A';
data(2).name = 'B';
% Is there a more straightforward way to achieve 'S.name = data.name' ?
names = {data.name};
[S.name] = names{:};
% Or a clean one liner that avoids using 'names' ?
0 件のコメント
採用された回答
Stephen23
2020 年 9 月 1 日
編集済み: Stephen23
2020 年 9 月 1 日
Matlabcalifragilisticexpialidocious:
[S.name] = deal(data.name)
2 件のコメント
Ben
2024 年 4 月 18 日
After seeing many arrayfuns/loops/etc. used as solutions for similar questions on this site, along with getting them suggested by LLM chat bots, this solution is just so satisfying
*feels good meme*
その他の回答 (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!