what is a valid handle for Matlab?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Kaustubha Govind
el 29 de Mzo. de 2011
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 comentarios
Kaustubha Govind
el 30 de Mzo. de 2011
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.
Más respuestas (1)
Andrew Newell
el 29 de Mzo. de 2011
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 comentarios
Andrew Newell
el 29 de Mzo. de 2011
That probably occurred because you hadn't run a simulation and plotted the result.
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!