MATLAB: How to eliminate the blank between subplot

figuresubplot

what i mean is to make subplot box close to each other

Best Answer

Use the set command and the position property. Here is one example with zero spacing between the 2x2 axes and a 0.1 frame around them:
figure, subplot(2,2,1),plot(rand(3)),set(gca,'xtick',[],'ytick',[])
subplot(2,2,2),plot(rand(3)),set(gca,'xtick',[],'ytick',[])
subplot(2,2,3),plot(rand(3)),set(gca,'xtick',[],'ytick',[])
subplot(2,2,4),plot(rand(3)),set(gca,'xtick',[],'ytick',[])
ha=get(gcf,'children');
set(ha(1),'position',[.5 .1 .4 .4])
set(ha(2),'position',[.1 .1 .4 .4])
set(ha(3),'position',[.5 .5 .4 .4])
set(ha(4),'position',[.1 .5 .4 .4])
Instead of getting the axes handles as figure children, you could also save them during creation as subplot.