Implementing a stop button in AppDesigner
24 views (last 30 days)
Show older comments
Currently, I have a run and stop button implemented in AppDesigner. When I click the run button, it runs another script on the PATH. When I click the stop button, I'd like it to find the running script and halt it from proceeding, whereever it currently is. Is there a way to track the PID of a .m script file currently running?
0 Comments
Accepted Answer
Guillaume
on 15 Jan 2020
PIDs are used by the OS to track executables. m scripts don't have PIDS they're run within a matlab executable. Assuming the m script is run by a different matlab session as the one running your App, you could kill that separate matlab. Otherwise, no matlab does not let you kill scripts.
6 Comments
Guillaume
on 17 Jan 2020
If you have the parallel toolbox, it would be the easiest method. However, I can't help with that I don't have the toolbox.
Without the toolbox, my approach would be to modify the processing function so that it periodically checks if it needs to stop (and give a chance for the UI to process the events).
Otherwise, indeed you're left with implementing your own multithreading. Yair has written an excellent series on the different solutions. Starts at: Explicit multi threading - part 1 but for you, part 4 is probably the most relevant.
More Answers (1)
jmore
on 25 Aug 2020
Edited: jmore
on 25 Aug 2020
You can get around not having the parallel computing toolbox by adding a pause(0) (not sure how this works, but it does).
function stopSim(app, event)
app.stop_sim = true;
end
while i<=100 && app.stop_sim == false
pause(0);
% do something until user pushes the stopSim button
end
Once the user pushes the stopSim button, for which function "stopSim" is a callback, then the app has enough time to fetch the updated propertie of the app, to app.stop_sim == true and hence it is able to terminate the while loop before reaching 100 iterations.
0 Comments
See Also
Categories
Find more on Downloads 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!