GUI中有时会用到subplot后,重新绘制单幅图。
如果只是简单的cla,只会清除最后一个subplot的图片。
这个问题最后找到的解决方案,就是逐一清除subplot后,再重新生产axes。
在GUI中还牵涉到变量的传递,显得稍微复杂一些。
subplot的callback中,设置共享变量
handles.ax1 = ax1; %ax1 = subplot(121);
handles.ax2 = ax2; %ax2 = subplot(122);
guidata(hObject,handles); %更新handles
在重新绘制单幅图的callback中,清除ax1和ax2,并设置新的axes
H=axes('parent',handles.uipanel3); %设置新的axes
set(H,'Visible','off'); %axes坐标轴不显示
if( isfield(handles,'ax1'))
cla(handles.ax1);
end
if( isfield(handles,'ax2'))
cla(handles.ax2);
end