Force quiet a callback function on Appdesigner?

I am using Matlab Appdesigner and want to be able to force quiet any callback function and any subfunction with in that callback function. I added a push button to my app named Cancel and put the following code with in the sub-function of the Excute callback function to stop it when I press cancel. However it takes time to quit the excustion of the callback function (Excute) because it doesn't start quiting untill it reaches out to the line where this code is at in the sub-function.
%Check for Cancel button press
if app.CancelButton.Value == true
app.CancelButton.Value = false; % To reactive the stop button
return
end
Is there any way to add a Canceling pushbutton to the app which overwrite everything as Ctrl-C does in the Command window?

8 comentarios

Rik
Rik el 17 de Nov. de 2021
Not as far as I'm aware, but you could consider calling this check more often in your code. This might have a performance penalty.
Faez Alkadi
Faez Alkadi el 17 de Nov. de 2021
Hello Rik,
Thanks for your reply. I tried doing that but my app has so many subfunctions and that has caused a lot of problems in the app. Not efficient. I'm surprised Matlab doesn't have Cancellation pushbutton yet !!!
Rik
Rik el 18 de Nov. de 2021
Working from memory, so maybe this doesn't work at all: you could look into using a timer object. I believe you can stop execution of the function by deleting the object.
Faez Alkadi
Faez Alkadi el 18 de Nov. de 2021
Editada: Faez Alkadi el 18 de Nov. de 2021
Could you please give an example? Let's say I want to stop Function named Func1. How can I use timer object to stop it while running?
Rik
Rik el 18 de Nov. de 2021
To find out I would have to look up the documentation and maybe google something like 'stop timer function matlab'. Did you try either of those?
Faez Alkadi
Faez Alkadi el 18 de Nov. de 2021
I actually looked that up but still not sure how to use it. I appreciate your help.
Rik
Rik el 18 de Nov. de 2021
I never use AppDesigner or timer objects myself either. What code did you try?
I actually still don't know how to start with timer object. However, I used uiconfirm now but still works as my previous code since it need to wait for the excution to reach the line in the subfunction where app.CancelButton.Value is checked.
app.CancelButton.Value = false;
selection = uiconfirm(app.UIFigure,'Cancel?',...
'Confirm Cancelling');
switch selection
case 'OK'
app.CancelButton.Value = true;
return
case 'Cancel'
app.CancelButton.Value = false;
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Preguntada:

el 17 de Nov. de 2021

Comentada:

el 18 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by