MATLAB Answers

Implementing a stop button in AppDesigner

31 views (last 30 days)
Faker Mayfield
Faker Mayfield on 15 Jan 2020
Commented: Guillaume on 17 Jan 2020
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?


Sign in to comment.

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.


Show 3 older comments
Guillaume on 15 Jan 2020
I'm not sure what you mean by exported, or by main method.
Indeed pause would not freeze the app, it explicitly instructs matlab to do other things (such as App events). However, if you were running a very long calculation (e.g. ismember(rand(1e4), rand(1e4)) or maybe even a very long for loop) then I suspect you'll find your App unresponsive.
Faker Mayfield
Faker Mayfield on 17 Jan 2020
Thanks for the responses!
In AppDesigner, there is an export button, which takes the .mlapp file and exports it to a .m file. By main method, I was referencing the start of my app that begins to kick off calculations.
Yes, it indeed becomes unresponsive when running long calculations, thanks for that point on pause. So, would running another instance of MATLAB in the background and communicating GUI responses via UDP/TCP resolve this or is the Parallel Computing Toolbox really the way to go?
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.

Sign in to comment.

More Answers (0)

Sign in to answer this question.