Reference to non-existent field error
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2019-10-18
if (exist('str') == 0); or if(exist('handles.mystructdata') == 0)
That is not correct syntax for or.
if ~exist('str', 'var') || ~isfield(handles, 'mystructdata')
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!