Borrar filtros
Borrar filtros

how can i have a button in one callback function pause the execution of another callback function

3 visualizaciones (últimos 30 días)
function pushbutton1_Callback(hObject, eventdata, handles)
%when this button is pressed i want the code that is executing in
%pushbutton2 to pause
end
function pushbutton2_Callback(hObject, eventdata, handles)
%some code
end
%i am using matlab version R2019b
%Thank you
  1 comentario
Adam Danz
Adam Danz el 27 de Mayo de 2021
Editada: Adam Danz el 27 de Mayo de 2021
@Joseph Kutteh this question doesn't differ much from the question you asked earlier this week and never replied to:
And it's no surprise that both questions describe the same solution with some minor differences.
How many people do you want working on your problem? Please take some time to learn from the solutions and if you've got follow-up questions, leave comments.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 27 de Mayo de 2021
Editada: Jan el 1 de Jun. de 2021
% Initialize in the CreateFcn: handles.Pause = false
function pushbutton1_Callback(hObject, eventdata, handles)
handles.Pause = (hObject.Value == 0);
guidata(hObject, handles);
end
function pushbutton2_Callback(hObject, eventdata, handles)
for k = 1:1000
disp(clock); % <-- This is the pseudo code
pause(0.5); % <-- Insert your real computations instead
% If button1 was pressed, stay in this loop:
while handles.Pause % [EDITED] WHILE instead of IF ?!
handles = guidata(hObject);
pause(0.2);
end
end
end
  3 comentarios
Jan
Jan el 1 de Jun. de 2021
I do not understand, what you are asking for. I've marked the dummy lines now, which I have inserted instead of the real computations.
Adam Danz
Adam Danz el 1 de Jun. de 2021
Editada: Adam Danz el 1 de Jun. de 2021
The while loop in Jan's answer 'pauses' execution if the pause-flag is set to true. This flag is set by pressing pushbutton1 which must be a togglebutton that has a binary state (on/off) (see the pushbutton1_Callback function in Jan's answer).
Note that execution isn't really paused. It's just stuck in the while loop until it gets the signal to escape.
Before you sink too much time into a GUI that appears to be created by GUIDE, note that,
>The GUIDE environment will be removed in a future release. After GUIDE is removed, existing GUIDE apps will continue to run in MATLAB® but they will not be editable in GUIDE - noted in r2021 documentation.
Other ways to implement pauses in Apps/GUIs.
  • waitfor - example using AppDesigner but can be implemented outside of AppDesigner, too.
  • uiprogressdlg with the Indeterminate option (requires uifigure which excludes GUIDE GUIs)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by