How to resume the program runing after a button press ?

조회 수: 5 (최근 30일)
Nora Khaled
Nora Khaled 2017년 8월 22일
댓글: Nora Khaled 2017년 8월 22일
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
Guillaume
Guillaume 2017년 8월 22일
편집: Guillaume 2017년 8월 22일
@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 2017년 8월 22일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by