Matlab draw 'subaxis' based subplots on specified 'axes'

조회 수: 2 (최근 30일)
Aaronne
Aaronne 2014년 3월 6일
Hi smart guys,
I am coding some GUI staff using Matlab. And I want to plot a figure with subfigures in one specified 'axes' using 'subaxis' method (which can be download on Matlab FX [subaxis.m][1]).
The program behaves quite right at first. As the subfigures are updating by one click button. Then the error pops-up. I simplify the problem and write some testing codes as following:
% 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')
The program is fine at this point and did what I expected. Now I press a button to update these subfigures, but still want to plot the subfigures in the specified axes called '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 shows up!!!
Error using axes
Invalid object handle
Not sure what to do as the error info is so brief. It seems the subaxis can only be plot to a specific 'axes' once.
Any help would be appreciated. Thanks very much. A.
[1]: http://www.mathworks.co.uk/matlabcentral/fileexchange/3696-subaxis-subplot

답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by