MATLAB: Why can I not create 3 subplots

subplot

This code deletes the second subplot when the third is created:
clc
figure(1); clf;
sp(1) = subplot(1,3,1, 'Parent', hfig);
set(sp(1),'Position',[0.02 0.05 0.30 0.80]);
sp(2) = subplot(1,3,2, 'Parent', hfig);
set(sp(2),'Position',[0.32 0.15 0.60 0.80]);
sp(3) = subplot(1,3,3, 'Parent', hfig);
set(sp(3),'Position',[0.22 0.25 0.50 0.80]);
But why???

Best Answer

subplot deletes any axes that are already where you're trying to put the new one. If you're going to set the position property of the axes manually anyway, why bother with subplot at all? Just use axes:
clc, figure(1); clf;
sp(1) = axes('Parent', hfig);
set(sp(1),'Position',[0.02 0.05 0.30 0.80]);
sp(2) = axes('Parent', hfig);
set(sp(2),'Position',[0.32 0.15 0.60 0.80]);
sp(3) = axes('Parent', hfig);
set(sp(3),'Position',[0.22 0.25 0.50 0.80]);