what is a valid handle for Matlab?

6 ビュー (過去 30 日間)
Julián Francisco
Julián Francisco 2011 年 3 月 29 日
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.

採用された回答

Kaustubha Govind
Kaustubha Govind 2011 年 3 月 29 日
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?
  2 件のコメント
Julián Francisco
Julián Francisco 2011 年 3 月 29 日
OK. But I found rare that, after closing the figure window, the handle of it still exists and the handle´s value points to the same memory address (i.e. the handle´s value does not change when is not already not valid). I thought that some handle´s property indicated that it was not valid but I did not find it.
I also would like you to run the mentioned example and you say me why I got the error message " "No valid plots for handles.PlotFigure{1,1}", when I run the program in debugging mode and I try to parse "handles.PlotFigure" in the Variable Editor window
Kaustubha Govind
Kaustubha Govind 2011 年 3 月 30 日
True, after you've closed the figure window, the handle is not valid. I don't know if there is a handle property that indicates this, but the function ISHANDLE does.
Regarding the message "No valid plots for handles.PlotFigure{1,1}" - I think you are misunderstanding what this menu (Plot Selector tool) does. Please see http://www.mathworks.com/help/techdoc/matlab_env/f10-51778.html#f10-59215 - the message that you see shows up whenever you select a variable that is not suitable for plotting. See the topic "Selecting Appropriate Variables" for more information.

サインインしてコメントする。

その他の回答 (1 件)

Andrew Newell
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 件のコメント
Andrew Newell
Andrew Newell 2011 年 3 月 29 日
That probably occurred because you hadn't run a simulation and plotted the result.
Julián Francisco
Julián Francisco 2011 年 3 月 29 日
I do think not so. I have checked it and I have got the same error message.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by