Stop a function before close request function finishes

Hi,
I am currently creating an app using App Designer and I'd like it to be fool proof as much as possible. My goal is the compute data from a serial port to a graph that will uptade in real time as long as one state button is pressed. This works perfectly, however when the program is closed while the state button is pressed, I get an error that says "Invalid or deleted obejct". I suppose that this is due to the fact that I am currently in the middle of a function (the one that appends the the graph) and I just close the program before letting the function finish.
I tried to force the state of the button to 0 when I close the program, but that doesn't change anything as I close the app before the function even finishes. I know that what I need to do is to force the state of the button to 0, return from the closing function, let the plot function finish one last time, then close the program again. I guess I could also have a pop up box that says to change the state of the button manually. However these methods do not seem really elegant to me and I'd like to have a way to automatize the whole process in a single confirmation.
Also, this error is only annoying as it does not affect the program in any way and only pops up in matlab once the program has finished. But still, I'd like to have a job well done, error-free.
Thanks in advance,
Nathaniel

2 Comments

Using the try/catch formula in your function could be a solution to avoid errors.
Yes, that works very well, thank you!

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 7 Mar 2019

Commented:

on 11 Mar 2019

Community Treasure Hunt

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

Start Hunting!