I've been working on a script that uses the VideoWriter class in order to write each frame generated to an avi file. Currently, I have to use control + C to end the script. This means that the file is not properly closed after the script ends, so if I open it in a video player I get an error due to the lock on the file. I have to manually execute a close statement on the file each time in matlab, which is tedious.
I've looked into the following possibilities:
*I tried using CloseRequestFcn to make the script end when the X button is clicked in the topright of the window. I can close the file here. Unfortunately, however, there does not appear to be a command that ends a script. "quit" exits matlab altogether, which forces me to restart matlab and wait for the IDE to reload.
*As best as I can tell keyboard handling is done with call back functions. I'm not really sure how you can tell the main script to end its loop from a callback function.
Thanks in advance.