Adding fields to a struct?

35 ビュー (過去 30 日間)
Nicholas Kavouris
Nicholas Kavouris 2022 年 8 月 8 日
回答済み: Bruno Luong 2022 年 8 月 8 日
I have an existing struct titled PR1Data. I would like to add a new field titled 'filename' to the structure, why is this so difficult to do? I only want the field to exist, i have tried the following methods with no results:
PR1Data=setfield(PR1Data,'filename',[1 2])
error: 'scalar structure required for this assignment'
PR1Data.filename='';
Same error
How can i simply add a new field to an existing struct?? this should not be this difficult

採用された回答

Bruno Luong
Bruno Luong 2022 年 8 月 8 日
[PR1Data.filename] = deal('');
or if you PR1Data is non empty
PR1Data(1).filename = '';

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by