MATLAB: How to adjust the position of a title in a subplot

subplottitle

So I have the following subplot:
With the following code:
figure
subplot(1,2,1)
imagesc(im);
axis equal;
axis off;
hold on;
plot(position(:,1),position(:,2),'o','MarkerEdgeColor','r','LineWidth',1.5,'MarkerSize',10);
title('Detected Particles', 'FontSize',14);
histpos = [0.5703,0.2707,0.3347,0.4897];
subplot('position',histpos)
hist(FWHM, 6)
colormap default
xlabel('FWHM', 'FontSize',16)
ylabel('Frequency', 'FontSize',16)
set(gca,'FontSize',14);
title('Histogram of FWHM Values', 'FontSize',16);
As you can see, the title for the first subplot is in an odd position and I can't figure out why. It doesn't do that when I have it as a regular figure and not a subplot.
Any suggestions for how to fix it?
Thanks

Best Answer

It's the axis equal that does it -- take out the axis off afterwards and you'll see the position of the title isn't all that funny after all.
The side-by-side subplot is squished horizontally; when you make axis equal that shrinks the image in the y direction but doesn't change the overall axis size.
To fix, make the following changes--
...
xlm=xlim; % retrieve x axis limits
title('Detected Particles','Position',[mean(xlm) xlm(1)],'FontSize',14); % use for title positioning
The axis equal leaves y axis scaled to make the same range as x-axis in center so postioning the title at center and start of x axis moves it to the top edge of the scale image. It's the left edge instead of right since images have origin at upper left instead of LL as a regular plot.