axes对象的句柄会消失,即首次调用有效,第二次就出现

axes对象的句柄会消失,即首次调用有效,第二次就从handles里边消失了,于是报错:


Answer:


This behavior is the result of a combination of the side effects of PLOT, the axes' "NextPlot" property, and the use of GUIHANDLES.



PLOT makes a call to the NEWPLOT function to determine which axes to use. Also, depending on the axes' "NextPlot" property, some of that axes' properties may be set to default values. If the property has the value "Replace", it will reset all of the axes' properties and delete all of the children of the axes. This includes the axes' "Tag" property, set to an empty string. If the "NextPlot" property is set to "ReplaceChildren", then NEWPLOT will only delete the axes' children and will not change the axes' other properties.


GUIHANDLES creates a structure containing the handles for all figure objects having a non-empty "Tag" value (thus having a valid fieldname for a structure). Since the axes' Tag will be an empty string after plotting, it will not be included in the handles structure that is output by GUIHANDLES.


There are two ways around this problem:


1) Do not use GUIHANDLES to get the "handles" structure. If you are using GUIDE and are working in a GUIDE-generated callback function, the "handles" structure will already exist as an input to the function. Also, GUIHANDLES is only intended for use in initializing the GUI. After the GUI is initialized, use the GUIDATA function to get the "handles" structure since the structure may be modified.


2) Set the axes' NextPlot property to 'replacechildren'. This way, the axes' Tag property won't be changed when PLOT calls NEWPLOT.





相关链接:http://www.ilovematlab.cn/thread-55768-1-1.html

http://cn.mathworks.com/matlabcentral/answers/160806-gui-reference-to-non-existent-field-axes1

http://cn.mathworks.com/matlabcentral/newsreader/view_thread/289093


原博客链接:
https://blog.csdn.net/niumengxy/article/details/51392293

猜你喜欢

转载自blog.csdn.net/zhu_wendao/article/details/88911486