How can I make a file be automatically closed after ending a running matlab script...
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
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.
0 comentarios
Respuesta aceptada
Walter Roberson
el 27 de Jun. de 2013
Have your loop check a flag to see if it should exit. Have one of the callbacks set the flag.
while true
drawnow();
should_exit = get(handles.SOMEHANDLE, 'value');
if should_exit; break; end
.......
end
Más respuestas (2)
Chris
el 27 de Jun. de 2013
2 comentarios
Walter Roberson
el 27 de Jun. de 2013
get() of the Value property of a uicontrol object retrieves the current state of the control, such as which item number is selected in a menu, or whether a button is current pressed in or not.
Whether this is "passing variables" around depends on how you think about graphic objects, as to whether the drawn graphic is the "real" object whose state is to be fetched "live", or if the storage variables associated with the graphic object are the "real" object. If the storage is the "real" object, then Yes, get() with a handle is a way of passing variables across scripts, but if the graphic is the "real" object, then No, what is being passed around is locator information rather than a variable.
Tom
el 28 de Jun. de 2013
What conditions do want to satisfy to make it close? Or rather, what is preventing you from using close(vidObj) ?
0 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!