我有一个带两个按钮的简单GUI。其中一个是绘制单个图,一个是绘制两个子图。但是,一旦我按下子画面选项,我就无法回到单曲图。我使用轴,无效对象句柄''得到错误''。请看下面我非常简单的例子:
function plot_push1_Callback(hObject, eventdata, handles)
load('test.mat')
axes(handles.axes1)
cla(handles.axes1,'reset')
plot(x,x.^(n+1));
function push_plot2_Callback(hObject, eventdata, handles)
load('test.mat')
axes(handles.axes1)
cla(handles.axes1,'reset')
subplot(2,1,1);
plot(x,x.^(0));
subplot(2,1,2);
plot(x,x);
答案 0 :(得分:2)
此处的主要问题是subplot
创建新的axes
对象(或转换当前轴)。在操作axes
对象时,您需要考虑这一点。
axes(handles.axes1);
subplot(2,1,1); % This is still handles.axes1
plot(x, x.^(0))
newax = subplot(2,1,2); % This is a new axes
plot(x, x);
如果您想在GUIDE中使用容器,我会定义uipanel
而不是axes
。然后,所有子图都可以在此面板中生效。
function plot_push1_callback(hObject, eventdata, handles)
% Make one plot in the panel
subplot(1,1,1, 'Parent', handles.panel);
plot(x, x.^(n+1));
function plot_push2_callback(hObject, eventdata, handles)
% Make the first subplot in the panel
subplot(2,1,1, 'Parent', handles.panel)
plot(x, x.^0);
% Make the second subplot in the panel
subplot(2,1,2, 'Parent', handles.panel)
plot(x, x)