I would recommend putting any checks in a function that itself opens the GUI then you simply don't even attempt to open the GUI if the checks fail. I have been caught out myself with bailing out on a GUI in the OpeningFcn and ending up with a ghost GUI that is in some hidden state.
should do the job though to close the window although not if you have put things in the CloseRequest function that you do not want to happen in this case.
As far as closing windows that have been opened during a session goes it is entirely down to your application really. As far as I know Matlab does not allow figures to be parented by other figures so I programmed a GUI Manager class that deals with launching GUIs and closes them all down automatically when the manager is deleted (which happens when the 'parent' window closes). Generally though you can just close them yourself in the DeleteFcn or CloseRequestFcn of your main window.
If you call uiwait with a figure handle you don't need an explicit uiresume so long as the figure is closed at some point as this will cause it to resume anyway. You can do a uiresume explicitly though to pair up with a uiwait that was not given a figure handle. Then you can delete the figure whenever you deem appropriate.
Best Answer