How to resume the program runing after a button press ?

5 views (last 30 days)
Hi !
I have a program script that opens a GUI. the user should press one of many buttons. and the value of a global variable will change depending on which button was pressed. then in the scribt that value will be used. the process will be repeated many times.
what happen now is after pressing the button I have to close the GUI for the rest of the program to run. so, I need a way to open the GUI once and for the rest of the program to run once one button is pressed.
the thing is I am so beginner in the whole GUI thing so I may need more detail or what exact function to use and where
thank you.
  5 Comments
Guillaume
Guillaume on 22 Aug 2017
Edited: Guillaume on 22 Aug 2017
@Nora,
There certainly are better mechanisms than global variables to pass data between programs.
With regards to your question, your design is not entirely clear. Showing us the code would help clarify. It sounds like you have two pieces of code that you want to run in parallel, a script and a GUI. If that is the case, then that is not possible in matlab. You would indeed need to close the GUI to continue the script. To achieve something similar to what you want you'll need to move the script code within the GUI code.
Nora Khaled
Nora Khaled on 22 Aug 2017
what I want is to start the code which will open a GUI and waits for a button to be pressed to continue the rest of the code.
so, this code is from the main script:
global tri_input;
while(game<=num_games)
tri_input=[0;0;0];
GUI_tri;
waitfor(GUI_tri);
%waitfor(tri_input);
fprintf('\n== game %d out of %d ==\n',game,num_games);
player_roadA(game)=tri_input(1); %input
fprintf(' A= %.0f',player_roadA(game));
player_roadB(game)=tri_input(2); %input
fprintf(' B= %.0f',player_roadB(game));
player_roadC(game)=tri_input(3); %input
fprintf(' C= %.0f',player_roadC(game));
fprintf('\n');
%then the rest of the code.
end % end while
and the GUI contain more than 50 buttons but it all doing the same (different values for the global var) :
function pushbutton26_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton26 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global tri_input;
tri_input=[4;1;5];
set(hObject, 'UserData', tri_input);
%tri_input
guidata(hObject, handles);
every thing works perfectly if after pressing the button I close the GUI window. but I want it to work from the moment of pressing the button.

Sign in to comment.

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!