フィルターのクリア

Changing field value for all fields in a struct

30 ビュー (過去 30 日間)
MiauMiau
MiauMiau 2014 年 4 月 3 日
コメント済み: deejt 2021 年 1 月 19 日
Hi
Given for instance I have a struct as follows:
s(2) = struct('name','anna','age',18)
s(1) = struct('name','bernd','age',22)
Now I want to change all the names to 'unknown', i.e. as well for s(1) as for s(2). How can I do it (this is just a toy example, I do have a 123 dimensional struct where I do not want to do it one by one). Thanks

採用された回答

Friedrich
Friedrich 2014 年 4 月 3 日
Hi,
without a loop:
[s.name] = deal('unknown')
  2 件のコメント
MiauMiau
MiauMiau 2014 年 4 月 3 日
wow thanks
deejt
deejt 2021 年 1 月 19 日
How would you proceed if you would only change the name 'anna' to unknown but leave 'bernd'?

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 3 日
s(2) = struct('name','anna','age',18)
s(1) = struct('name','bernd','age',22)
n=numel(s)
for k=1:n
s(k).name='unknown'
end

カテゴリ

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