Replacement of Structure array field with array

18 ビュー (過去 30 日間)
Tom
Tom 2017 年 5 月 17 日
コメント済み: Tom 2017 年 5 月 17 日
I have a structure with a field. I want to replace the field value for each element of the structure. I thought that this would work since it returns the values, but it errors out: [S.x] = 1:10
Want to vectorize this: for i = 1:10 S(i).x = i; end
I've seen similar questions, but nothing that seemed to work.
Thanks!

採用された回答

Stephen23
Stephen23 2017 年 5 月 17 日
編集済み: Stephen23 2017 年 5 月 17 日
  1 件のコメント
Tom
Tom 2017 年 5 月 17 日
To do this with a direct typing took me a bit to figure out: [S.x] = deal(1,2,3,4,5,6,7,8,9,10);
Not sure why I need to use deal, when [S.x] = C{:}; doesn't.
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by