chain together GUIs in MATLAB

3 次查看(过去 30 天)
Andrew McReynolds
Andrew McReynolds 2020-3-20
评论: Rik 2020-3-23
I am trying to create a program in matlab that chains together several tested, functioning GUIs but I am having some trouble.
In one function I have:
global Status;
global value1;
Status = 'setup';
switch Status
case 'setup'
ADone = ASetup; %Calls setup function which should return a value when done
if strcmp(ADone, 'yes')==1
Status = 'Pos1';
end
case 'Pos1'
value1 = OHMgui1;
Status = 'Pos2';
case 'Pos2'
%Still work in progress
end
And in my Asetup function I have:
function done = ASetup
AStatus = GUI1;
BStatus = GUI2();
CStatus = GUI3();
DStatus = GUI4();
%Up until here everything goes as intended
Refstatus = RefGUI();
done = 'yes'; %Returns value when finished
disp (done) %Check statement, does not execute, error happens somewhere before here
end
GUIs 1-4 basically just display reference images with an OK button to close them, and I control them by using uiwait() and having them set a return value when the OK button is pushed (to make sure one doesn't trigger until the previous one is closed). This functions exactly as I would like.
However for RefGUI, I created it with a continue and a close button. I want the user to be able to click continue and have the program continue while RefGUI stays open. Ideally this would result in a call OHMGUI1, but it doesn't even seem to display the check statement.
I suspect the error is in RefGUI, which opens at the correct time, but I cannot get anything to happen after the continue or close buttons are pressed (with the exception of closing the GUI without the program continuing). Its code is:
function varargout = RefGUI(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ClampRef_OpeningFcn, ...
'gui_OutputFcn', @ClampRef_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
function RefGUI_OpeningFcn(hObject, eventdata, handles, varargin)
matlabImage = imread('C:...reference.jpg');
image(matlabImage)
axis off
axis image
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.pushbutton2,'enable','off') %Disable close button until continue is pressed
function varargout = RefGUI_OutputFcn(hObject, eventdata, handles)
uiwait();
global valueout;
varargout{1} = valueout;
%I have also tried disabling the above 3 lines with no difference.
function pushbutton1_Callback(hObject, eventdata, handles)
global valueout;
valueout = 'Finished';
set(handles.pushbutton2,'enable','on') %enable close button
set(handles.pushbutton1,'enable','off') %disable continue button
return
function pushbutton2_Callback(hObject, eventdata, handles)
closereq(); %close button closes GUI window
What can I do to make the program continue as intended?

回答(1 个)

Andrew McReynolds
Andrew McReynolds 2020-3-21
I got rid of the switch case, moved the display statement before setting the return value, and used UIresume(); Now it works
  3 个评论
Andrew McReynolds
Andrew McReynolds 2020-3-22
编辑:Andrew McReynolds 2020-3-22
I did for some functions, but for the GUI programs i don't know of any other way to make the variables visible to and editable by several functions unless I start playing with inputs and outputs (since this is my first time experimenting with GUIs in matlab and in general, I'd like to leave most of the GUIDE-generated code as-is). For something like the variable that I want to display on the screen and update when the user pushes buttons on a calculator-like GUI, using a global variable seems to work exactly as intended.
Rik
Rik 2020-3-23
You can use the handles to the different GUIs to retrieve their guidata just before they close. I would suggest moveing away from GUIDE. It is probably holding you back in understanding how it works (although I can see from your edited down code in your question you seem to at least get the basics). If you want some helpful advice I would encourage you to check out this thread.
You could even consider a class-based GUI like my example in that thread if you want to preserve the input after the GUI has been closed.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by