Trying to return value from a GUIDE GUI causes struct error
1 次查看(过去 30 天)
显示 更早的评论
I want to make a simple popup window for my main Gui, which would have a few input fields and an Apply button. I start the filterDialog() popup in my main code, and attempt to return something when it exits. I was following the instructions I found here
I am getting an error
Struct contents reference from a non-struct array object.
Error in filterDialog>filterDialog_OutputFcn (line 74)
varargout{1} = handles.output;
---------------------------
function varargout = filterDialog(varargin)
% FILTERDIALOG MATLAB code for filterDialog.fig
% FILTERDIALOG, by itself, creates a new FILTERDIALOG or raises the existing
% singleton*.
%
% H = FILTERDIALOG returns the handle to a new FILTERDIALOG or the handle to
% the existing singleton*.
%
% FILTERDIALOG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FILTERDIALOG.M with the given input arguments.
%
% FILTERDIALOG('Property','Value',...) creates a new FILTERDIALOG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before filterDialog_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to filterDialog_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help filterDialog
% Last Modified by GUIDE v2.5 08-Mar-2018 14:14:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @filterDialog_OpeningFcn, ...
'gui_OutputFcn', @filterDialog_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before filterDialog is made visible.
function filterDialog_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to filterDialog (see VARARGIN)
% Choose default command line output for filterDialog
handles.output = "SomeExampleOutput";
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes filterDialog wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = filterDialog_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% The figure can be deleted now
delete(handles.figure1);
function figure1_CloseRequestFcn(hObject, eventdata, handles)
if isequal(get(hObject,'waitstatus'),'waiting')
uiresume(hObject);
else
delete(hObject);
end
% --- Executes on button press in filterApplyButton.
function filterApplyButton_Callback(hObject, eventdata, handles)
% hObject handle to filterApplyButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
9 个评论
Adam
2018-3-9
Try the attached files. To be honest I'm not sure what was wrong, but the CloseRequestFcn was not being called. All I did was go into GUIDE and right click the figure and select CloseRequestFcn from the View Callbacks and it then took me to the function you had already written so it seemed to think it was linked correctly. After that, however, it now works for me where it didn't before. Sometimes callbacks can get into this kind of state where they are not properly linked to the controls, I'm not sure what causes it, but doing what I did generally sets it straight again.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!