%function subplotfix()

h=get(gcf,'Children');
j=0;
for i=1:length(h)
   if isempty(get( h(i),'UserData'))==1
       j=j+1;
       H(j)=h(i);
   end    
end    
%H=flipud(H');
n=length(H);
for i=2:n
 set(H(i),'XTickLabel','');
end 
for i=1:n
    p(i,:)=get(H(n-i+1),'Position');
end    

for i=1:n-1
 dd(i)=(p(i,2)-(p(i+1,2)+p(i+1,4)));
end
dy=sum(dd)/n;

p(n,4)=p(n,4)+dy;
%p(n,2)=p(n,2)-dy;
%p(n,4)=p(n,4)+dy;

if n>2
 for i=2:n-1
    p(i,2)=p(i,2)-dy/2;
    p(i,4)=p(i,4)+dy;
 end
end 
%p(1,4)=p(1,4)+dy;
p(1,2)=p(1,2)-dy;
p(1,4)=p(1,4)+dy;
for i=1:n
 set(H(n-i+1),'Position',p(i,:));
end

for i=1:n-1
 str=get(H(i),'YtickLabel');
 str(length(str),:)=' ';
 set(H(i),'YtickLabel',str)
 val=get(H(i),'Ytick');
 val=val(1:length(val));
 set(H(i),'Ytick',val)
end