How do I code matlab to recheck while loops before continuing?

1 visualizzazione (ultimi 30 giorni)
Im trying to build a code that switches between codes based on button inputs. I want to first assign the variable exe=1 and then run while loops as exe=1, exe=2, exe=3 ... until exe=0 which means all conditions are met and the loop closes. Currently I have the main code of:
%%%%%Begining of Script %%%%%
global exe
exe=1;
while exe==1
main_menu=uicontrol('Style','pushbutton','Position',[20 20 100 100],'String','Pong','Callback',@setexe2);
return
end
while exe==2
main_menu2=uicontrol('Style','pushbutton','Position',[20 20 100 100],'String','Pong','Callback',@setexe1);
return
end
%%%%%End of Script %%%%%
I also have two function.m files used as callbacks for the uicontrol as follows
setexe1.m
function setexe1 (src,event)
global exe
exe=1;
close
end
setexe2
function setexe2 (src,event)
global exe
exe=2;
close
end
When I run the code, it does create a figure with the first button, and when I press the button, it closes the window and sets exe=2. But once the figure disappears, the next figure does not appear. What should I add and what should I change in order to be able to do the following.
%while exe=1
% create button1
% if button1 is pressed
% close window and set exe=2
%while exe=2
% create button2
% if button2 is pressed
% close window and set exe=1
%if exe=1 or 2
% return to top
%if exe=0
% end script
MATLAB 2018a Student Edition

Risposte (1)

James Tursa
James Tursa il 12 Apr 2018
Maybe something like this logic is what you need, although you don't specify a way to get exe set to 0 so you would have to add some more logic for that.
exe = 1;
while( exe ) % while exe is nonzero
if( exe==1 )
% create button1
% if button1 is pressed
% close window and set exe=2
end
if( exe==2 )
% create button2
% if button2 is pressed
% close window and set exe=1
end
end

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by