MATLAB: What is a valid handle for Matlab

guihandlesMATLABsimulink

Hi. I am newbie with Matlab. I am learning through the Matlab Documentation. In these moments, I am doing the example "A GUI to Set Simulink Model Parameters" ( http://www.mathworks.com/help/techdoc/creating_guis/f6-8865.htm ). At the section "Closing the GUI" of the mentioned one, it appears the following code for the Close button callback:
function CloseButton_Callback(hObject, eventdata, handles)
% Close the GUI and any plot window that is open
if isfield(handles,'PlotFigure') && ...
ishandle(handles.PlotFigure),
close(handles.PlotFigure);
end
close(handles.F14ControllerEditor);
I am trying to understand what a valid handles is by parsing the behaviour of the handle "handles.PlotFigure". I have inserted a breakpoint in the line number four of the code above (ishandle(handles.PlotFigure),) and I have run the program in debugging mode. After doing that, my conclusion is:
– A valid handle (in this case a Handle Graphics Object called handles.PlotFigure) is an object which has not been deleted (closed) by some command.
However, I do not understand why the handles field "handles.PlotFigure" remains in the the handles structure since it should have been deleted too. Another surprise I found out while I was debugging was that the Variable Editor said "No valid plots for handles.PlotFigure{1,1}". I also understand this because the figure for handles.PlotFigure did exist.
I would be thankful if someone run the example and can explain me my doubts.
Thank you very much for your attention. Best regards.

Best Answer

Although the field handles.PlotFigure is not deleted, the code verifies the validity of the handle using the ISHANDLE function. The handle would have be valid as long as the figure window whose handle is stored in handles.PlotFigure is open.
Does this answer your question?