フィルターのクリア

save part of a stucture

49 ビュー (過去 30 日間)
Daniel Boateng
Daniel Boateng 2019 年 4 月 1 日
編集済み: Guillaume 2019 年 4 月 1 日
I have a matlab struct Data with these different fieldnames.Please how do I save just the fields (name, time and version) in both Data(1) and Data(2) without having to save all the struct. I tried
save('C:\danny\Pro', '-struct', 'Time','name','Version') % but it isnt working.
save('C:\danny\Pro', '-struct', 'Data', 'Time','name','Version')
Data(1).name = 'to be filled';
Data(1).Time = datestr(now);
Data(1).Project = 'LastProject.mat';
Data(1).SimulationParam = 2000;
Data(2).Version = 'Version 2.2';
Data(2).name = 'to be filled';
Data(2).Time = datestr(now);
Data(2).Project = 'LastProject.mat';
Data(2).SimulationParam = 2000;
Data(2).Version = 'Version 2.2';
save('C:\danny\Pro', '-struct', 'Data', 'Time','name','Version')

採用された回答

Guillaume
Guillaume 2019 年 4 月 1 日
編集済み: Guillaume 2019 年 4 月 1 日
The -struct option of save saves each field of the structure as individual variables. Obviously for that to work the structure has to be scalar.
If you want to actually save the structure, then you don't want the struct option. To only save some fields, you'll have to either remove the unwanted fields or just copy the wanted fields into a new structure array. It's probably easier to remove the unwanted fields:
datatosave = rmfield(Data, setdiff(fieldnames(Data), {'Time', 'name', 'Version'})); %remove all fields but Time, name and Version
save('C:\danny\Pro', 'datatosave')

その他の回答 (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