Question

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).

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.

No correct solution

OTHER TIPS

Remove these two lines from the top of your second piece of code:

axes(ax); 
cla(ax, 'reset');

Now matlab will update the graph in the current plot. I have tested this in a normal (non-GUI) matlab file and it works fine. If it doesn't work for you, post details of the GUI as there may be some related problem within.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top