Reference to non-existent field error

1 visualización (últimos 30 días)
MHS
MHS el 18 de Oct. de 2019
Comentada: Stephen23 el 18 de Oct. de 2019
Hello Everyone. I am getting an error related to
Reference to non-existent field 'mystructdata'.
Error in GUI_ParametersFinal>pushbutton_Save_Callback (line 120)
data = handles.mystructdata;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI_ParametersFinal (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI_ParametersFinal('pushbutton_Save_Callback',hObject,eventdata,guidata(hObject))
When I do not type any value inside the edit text boxes, it gives me this error when saving inside the mat file. How can I remove this error and save another value only, which is needed and not related to my struct fields.
My code for pushbutton save_ callback is this:
function pushbutton_Save_Callback(hObject, eventdata, handles)
startingFolder = pwd
defaultFileName = fullfile(startingFolder, '*.mat');
[baseFileName, folder] = uiputfile(defaultFileName, 'Select mat file');
if baseFileName == 0
return;
end
fullFileName = fullfile(folder, baseFileName);
if (exist('str') == 0); or if(exist('handles.mystructdata') == 0)
data.Level = handles.Level;
save(fullFileName,'data')
else
data = handles.mystructdata;
data.Level = handles.Level;
save(fullFileName,'data');
end
If I dont type anything inside the edit text boxes, I will like these text boxes to be ignored and just save that text box value in which I typed a value using structs fields. Thank you so much.
  1 comentario
Walter Roberson
Walter Roberson el 18 de Oct. de 2019
if (exist('str') == 0); or if(exist('handles.mystructdata') == 0)
That is not correct syntax for or.
if ~exist('str', 'var') || ~isfield(handles, 'mystructdata')

Iniciar sesión para comentar.

Respuesta aceptada

Adam
Adam el 18 de Oct. de 2019
exist('handles.mystructdata')
does not work for struct fields.
isfield( handles, 'mystructdata' )
is what you should use to check if the field exists.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Properties 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