MATLAB: Need basic help w/ GUI Programming

callbacksguiprogram flowreturn values

Hi, folks! A little chagrinned to ask such a simple q, but I've been beating my head against the doc for a while now and getting (almost) nowhere.
I've built a GUI using GUIDE and need to get the user input back to the calling/creating program; I've done this before…by "cheating," i.e., by using globals, but I know this is not the way it's supposed to be done (and the guy I work w/ here, who generally knows more about all this stuff than I do, does it that way 'cause he hasn't been able to figure out the "right" way to do it either).
OK, so I have this gui consisting of a bunch of 'edit' uicontrols and a "Done" pushbutton and a "Cancel" pushbutton–I want the values in the edit controls to be passed back to the calling program when the user clicks on Done (and an empty array to be returned if s/he clicks Cancel). So far all I've been able to figure out how/what to do is to put the uiwait at the end of the GUI creation function, and the uiresume's at the end of the pushbuttons' respective Callbacks. The gui is created fine and the uiwait appears to behave properly, but when I click on either pushbutton, the callbacks aren't entered (I have breakpoints at each of their first lines and they're never reached) and I get the following error:
Error using FilterGUI
Too many input arguments.
Error in
FilterGUI>@(hObject,eventdata)FilterGUI('Done_Callback',hObject,eventdata,guidata(hObject))
(line 328)
'Callback',@(hObject,eventdata)FilterGUI('Done_Callback',hObject,eventdata,guidata(hObject)),...
Error using waitfor
Error while evaluating uicontrol Callback
Here's a pared down version of my code:
function h1 = FilterGUI()
appdata = [];
appdata.GUIDEOptions = struct(...
'active_h', [], ...
'taginfo', struct(...
'figure', 2, ...
'text', 19, ...
'uitable', 2, ...
'edit', 2, ...
'pushbutton', 3), ...
'override', 1, ...
'release', 13, ...
'resize', 'none', ...
'accessibility', 'off', ...
'mfile', 0, ...
'callbacks', 1, ...
'singleton', 1, ...
'syscolorfig', 1, ...
'blocking', 0, ...
'lastFilename', 'C:\Data\My Documents\JobRelated\MWDMS\MWDataMgmt\RT\Dev\Flights\FilterGUI.fig');
appdata.lastValidTag = 'figure1';
appdata.GUIDELayoutEditor = [];
appdata.initTags = struct(...
'handle', [], ...
'tag', 'figure1');
h1 = figure(...
'Units','characters',...
'Color',[0.925490196078431 0.913725490196078 0.847058823529412],...
'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
'IntegerHandle','off',...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'MenuBar','none',...
'Name','Filter Time Constantant Selection',...
'NumberTitle','off',...
'PaperPosition',get(0,'defaultfigurePaperPosition'),...
'Position',[103.666666666667 30.5 52.8333333333333 31],...
'Resize','off',...
'HandleVisibility','callback',...
'UserData',[],...
'Tag','figure1',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
appdata = [];
appdata.lastValidTag = 'text2';
h2 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'FontSize',11,...
'HorizontalAlignment','left',...
'Position',[1.83333333333333 27.875 22.3333333333333 1.625],...
'String','Pressure',...
'Style','text',...
'Tag','text2',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
appdata = [];
appdata.lastValidTag = 'text11';
h11 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'BackgroundColor',[1 1 1],...
'FontSize',11,...
'HorizontalAlignment','left',...
'Position',[26.8333333333333 25 22.3333333333333 1.625],...
'String','0.1',...
'Style','edit',...
'Tag','text11',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
appdata = [];
appdata.lastValidTag = 'DoneButton';
h20 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'Callback',@(hObject,eventdata)FilterGUI('Done_Callback',hObject,eventdata,guidata(hObject)),...
'FontSize',14,...
'Position',[5.16666666666667 1.0625 15.1666666666667 2.375],...
'String','Done',...
'Tag','DoneButton',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
%local_CreateFcn(h20, [], '', appdata);
appdata = [];
appdata.lastValidTag = 'CancelButton';
h21 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'BackgroundColor',[1 1 1],...
'Callback',@(hObject,eventdata)FilterGUI('Cancel_Callback',hObject,eventdata,guidata(hObject)),...
'FontSize',14,...
'Position',[29.3333333333333 1.0625 16 2.375],...
'String','Cancel',...
'Tag','CancelButton',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );
%local_CreateFcn(h21, [], '', appdata);
uiwait(h1)
% --- Set application data first then calling the CreateFcn.
function local_CreateFcn(hObject, eventdata, createfcn, appdata)
if ~isempty(appdata)
names = fieldnames(appdata);
for i=1:length(names)
name = char(names(i));
setappdata(hObject, name, appdata.(name));
end
end
if ~isempty(createfcn)
if isa(createfcn,'function_handle')
createfcn(hObject, eventdata);
else
eval(createfcn);
end
end
function out = Done_Callback(varargin)
out = char(get(findall(get(hObject, 'Parent'),'Style','edit'), 'String'));
uiresume
function out = Cancel_Callback(varargin)
out = 0;
uiresume
Except for the 'CreateFcn' property-setting lines, the syntax of the pushbutton creation commands is consistent with that in my other GUI's (i.e., the ones in which I "cheated"; the commented out "local_CreateFcn" lines, which are the modus operendi in my other GUI's, were my attempt to see if that was the problem–it did not appear to be, but I've left them in just in case it strikes someone as important).
Oh, and I should also mention that the use of varargin arguments to the Callbacks, which differs from my "working" GUIs, were another (unsuccessful) attempt to "fix" the "Too many input arguments" error (thus, clearly (?), something else is complaining about receiving too many inputs).
Anyway, from my reading, I kind of gather that I should be using the variable "guidata" in some way, but it remains far from clear to me how, and obviously there's also some aspect of program flow that I'm still not getting–I wish I could use wxPython for this! 🙁
Please help!
Thanks!

Best Answer

Going through some of the examples here http://www.mathworks.com/help/techdoc/creating_guis/f6-6010.html or watching Doug's video might be beneficial to you.