我正在使用Matlab编写一些GUI人员。我想使用'subaxis'方法在一个指定的'轴'中绘制带有子图的图形(可以在Matlab FX subaxis.m上下载)。
该程序最初表现得非常正确。由于子图片通过一个单击按钮更新。然后弹出错误。我简化了问题并编写了一些测试代码如下:
% Specify an 'axes' in my GUI (here is an example of axes handle called 'ax')
ax = axes;
axes(ax);
cla(ax, 'reset');
% Plot something using 'subaxis' with multiple subfigures
x = 0:0.1:10;
spacing = 0.0;
subaxis(3,1,1,'Spacing',spacing);
plot(x,rand(size(x)),'k')
legend('D','Location','NorthWest')
ylim([-0.2 1])
set(gca, 'box','off')
set(gca,'XAxisLocation','top')
subaxis(2,'Spacing',spacing);
plot(x,rand(size(x)),'r')
legend('C','Location','NorthWest')
ylim([-0.2 1])
set(gca,'xtick',[],'box','off','xcolor','w')
subaxis(3,'Spacing',spacing);
plot(x,rand(size(x)),'b')
legend('B','Location','NorthWest')
set(gca, 'box','off')
此时该计划很好,并达到了我的预期。现在我按下一个按钮来更新这些子图,但仍想在指定的轴上绘制名为'ax'的子图:
axes(ax);
cla(ax, 'reset');
x = 0:0.1:10;
spacing = 0.0;
subaxis(3,1,1,'Spacing',spacing);
plot(x,rand(size(x)),'k')
legend('D','Location','NorthWest')
ylim([-0.2 1])
set(gca, 'box','off')
set(gca,'XAxisLocation','top')
subaxis(2,'Spacing',spacing);
plot(x,rand(size(x)),'r')
legend('C','Location','NorthWest')
ylim([-0.2 1])
set(gca,'xtick',[],'box','off','xcolor','w')
subaxis(3,'Spacing',spacing);
plot(x,rand(size(x)),'b')
legend('B','Location','NorthWest')
set(gca, 'box','off')
出现错误!!!
Error using axes
Invalid object handle
不确定该怎么做,因为错误信息非常简短。似乎子轴只能绘制一次特定的“轴”。
任何帮助将不胜感激。非常感谢。甲
答案 0 :(得分:0)
从第二段代码的顶部删除这两行:
axes(ax);
cla(ax, 'reset');
现在matlab将更新当前图表中的图表。我已经在普通(非GUI)matlab文件中对此进行了测试,它运行正常。如果它不适合您,请发布GUI的详细信息,因为可能存在一些相关问题。