How do I delete a field variable from a structure
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Martin
am 19 Feb. 2012
Kommentiert: Trung Hieu Le
am 6 Jun. 2016
I have variable in gui: handles.Data; Data is type: 70x50x2 logical. I need to delete the variable data. When i write: delete(handles.Data); or clean(handles.Data); then get an error: Argument must contain a string. :(
Thank you
1 Kommentar
Akzeptierte Antwort
Jiro Doke
am 19 Feb. 2012
handles.Data is a field of variable handles. To delete a field,
handles = rmfield(handles. 'Data');
To set the field to empty,
handles.Data = [];
Weitere Antworten (2)
Image Analyst
am 19 Feb. 2012
Try this robust code, to avoid errors:
% Try to remove the field called Data, if there is one.
% First see if there is a field called "Data."
hasField = isfield(handles, 'Data') % Will be True or False.
% Now remove it if it's there.
if hasField
% Field is there. Remove it.
handles = rmfield(handles, 'Data')
else
% Field is not there, warn user.
warningMessage = sprintf('Warning: the structure "handles"\ndoes not have a field called "Data."');
uiwait(warndlg(warningMessage));
end
2 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!