How do I delete a field variable from a structure

43 visualizaciones (últimos 30 días)
Martin
Martin el 19 de Feb. de 2012
Comentada: Trung Hieu Le el 6 de Jun. de 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 comentario
Jiro Doke
Jiro Doke el 19 de Feb. de 2012
I'm going to rename the title to better reflect the question.

Iniciar sesión para comentar.

Respuesta aceptada

Jiro Doke
Jiro Doke el 19 de Feb. de 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 = [];
  1 comentario
Martin
Martin el 19 de Feb. de 2012
Finally, it works as follows: handles=rmfield(handles,'Data');
Thx!

Iniciar sesión para comentar.

Más respuestas (2)

Jan
Jan el 19 de Feb. de 2012
Same effect as rmfield, but about 10 times faster: FEX: fRMField

Image Analyst
Image Analyst el 19 de Feb. de 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 comentarios
Martin
Martin el 20 de Feb. de 2012
great, it'll use
thx
Trung Hieu Le
Trung Hieu Le el 6 de Jun. de 2016
Thanks for this answer. It is perfect.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by