Reference to non-existent field error

1 vue (au cours des 30 derniers jours)
MHS
MHS le 18 Oct 2019
Commenté : Stephen23 le 18 Oct 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 commentaire
Walter Roberson
Walter Roberson le 18 Oct 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')

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by