MATLAB: Generic modal question dialog error on close

error close windowMATLAB

I created a generic modal question dialog using GUIDE. It's a simple yes/no question dialog. If I try to close the window using the x in the top right corner rather than clicking a button, when it gets to varargout{1} = handles.output I get the error "Attempt to reference field of non-structure array." If I click one of the buttons it works fine, it's only if I try to close the window without clicking a button. I'm using MATLAB R2015a. I didn't change anything, this is the generic yes/no question dialog pre-built in GUIDE. By the way, this is in the OutputFcn. I have a gui I set up similarly as far as OpeningFcn and OuptputFcn go, which is how I discovered the problem in the first place. I noticed they were set up similarly and decided to try the built-in question dialog to see what the difference was when I found out it does the same thing. I attached the m file for my project.

Best Answer

I did a lot of digging (2 days) I stumbled across this: Problems with GUI deleting handles before output function and it seems to work. I don't know how 'clean' of an answer it is, I'm by far no Matlab expert, but it works well and still returns the default values setup in OpeningFcn