what is a valid handle for Matlab?
이전 댓글 표시
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.
채택된 답변
추가 답변 (1개)
Andrew Newell
2011년 3월 29일
The function close calls delete, so what you are seeing is the behavior of delete. Note these two statements: "delete(h) deletes the graphics object with handle h ... When deleted, any references to the objects in handle_array become invalid. To remove the handle variables, use the clear function."
The reason for this curious behavior is that you can make other handles refer to the same graphics object, for example:
h = plot(1:10);
g = h;
Then if you delete g, h also becomes a non-handle variable:
delete(g)
get(h)
??? Error using ==> get
Invalid handle object.
I suppose it works this way because it's too cumbersome to keep track of all the handle variables referring to the same object.
I don't know how you got the message "No valid plots for handles.PlotFigure{1,1}".
댓글 수: 3
Julián Francisco
2011년 3월 29일
Andrew Newell
2011년 3월 29일
That probably occurred because you hadn't run a simulation and plotted the result.
Julián Francisco
2011년 3월 29일
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!