% Drea Thomas 6/15/95 drea@mathworks.com

% Warning: If the figure or axis units are non-default, this
% will break.

% Parameters used to position the supertitle.

% Amount of the figure window devoted to subplots
plotregion =3D .92;

% Y position of title in normalized coordinates
titleypos  =3D .95;

% Fontsize for supertitle
fs =3D get(gcf,'defaultaxesfontsize')+3;

% Fudge factor to adjust y spacing between subplots
fudge=3D1;

haold =3D gca;
figunits =3D get(gcf,'units');

% Get the (approximate) difference between full height (plot + title
% + xlabel) and bounding rectangle.

=09if (~strcmp(figunits,'pixels')),
=09=09set(gcf,'units','pixels');
=09=09pos =3D get(gcf,'position');
=09=09set(gcf,'units',figunits);
=09else,
=09=09pos =3D get(gcf,'position');
=09end
=09ff =3D (fs-4)*1.27*5/pos(4)*fudge;

        % The 5 here reflects about 3 characters of height below
        % an axis and 2 above. 1.27 is pixels per point.

% Determine the bounding rectange for all the plots

% h =3D findobj('Type','axes');  =20

% findobj is a 4.2 thing.. if you don't have 4.2 comment out
% the next line and uncomment the following block.
=09
% h =3D findobj(gcf,'Type','axes');  % Change suggested by Stacy J. Hills

% If you don't have 4.2, use this code instead
ch =3D get(gcf,'children');
h=3D[];
for i=3D1:length(ch),
  if strcmp(get(ch(i),'type'),'axes'),
    h=3D[h,ch(i)];
  end
end

=09


max_y=3D0;
min_y=3D1;

oldtitle =3D0;
for i=3D1:length(h),
=09if (~strcmp(get(h(i),'Tag'),'suptitle')),
=09=09pos=3Dget(h(i),'pos');
=09=09if (pos(2) < min_y), min_y=3Dpos(2)-ff/5*3;end;
=09=09if (pos(4)+pos(2) > max_y), max_y=3Dpos(4)+pos(2)+ff/5*2;end;
=09else,
=09=09oldtitle =3D h(i);
=09end
end

if max_y > plotregion,
=09scale =3D (plotregion-min_y)/(max_y-min_y);
=09for i=3D1:length(h),
=09=09pos =3D get(h(i),'position');
=09=09pos(2) =3D (pos(2)-min_y)*scale+min_y;
=09=09pos(4) =3D pos(4)*scale-(1-scale)*ff/5*3;
=09=09set(h(i),'position',pos);
=09end
end

np =3D get(gcf,'nextplot');
set(gcf,'nextplot','add');
if (oldtitle),
=09delete(oldtitle);
end
ha=3Daxes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
ht=3Dtext(.5,titleypos-1,str);set(ht,'horizontalalignment','center','font=
size',fs);
set(gcf,'nextplot',np);
axes(haold);
if nargout,
=09hout=3Dht;
end
