I have a "play" button attached to the "ButtonPlayPushed" callback which plots a dynamic graph (with the function imagesc()).
How can I program a stop button that stops the action of the "play" button?

 Réponse acceptée

Mario Malic
Mario Malic le 13 Sep 2020
Modifié(e) : Mario Malic le 13 Sep 2020

2 votes

Actually,
In callback for the stop button, set app.stopFlag = true;
Within the plotting function check the property
% You're probably plotting with for loop or something similar,
% so include this into it
if app.stopFlag % assuming app.stopFlag=true means process should abort
return
end
Read this as well.
Credits out to Adam's answer from my similar question
You can use a callback function to change the value of a flag that is checked repeatedly within the plotting commands.
Define the flag as a public property of the app (see instructions) so the external function has access to the flag.
The app's startup function would set the flag to false: app.stopFlag = false;
The callback function would merely set the flag to true: app.stopFlag = true;
Within the external (or internal) function, you can use the condition,
if app.stopFlag % assuming app.stopFlag=true means process should abort
return
end
Note that if you return before the function is complete, you'll need to assign default output values and you may need to add return commands to any other invoking functions.
Then, the flag should be reset: app.stopFlag=false.

4 commentaires

Palma Errico
Palma Errico le 13 Sep 2020
Thanks Mario the code is good.
The only thing, when stopFlag = true I don't want the window to close but only to stop the plot (and save the data I know how to do) is it possible to do it?
Mario Malic
Mario Malic le 13 Sep 2020
Modifié(e) : Mario Malic le 13 Sep 2020
I am not sure how exactly should be done as it may depend on the plot code. Try with break instead of return, as break exits for or while loop, whereas return exits the function (if your plot was located in a function, then it would be working properly I think).
Palma Errico
Palma Errico le 14 Sep 2020
thanks Mario it was just what i wanted.
With the right changes the app works with break
Mario Malic
Mario Malic le 14 Sep 2020
Great to hear!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by