MATLAB: How to add different titles to multiple image display using subplot

imagemultiplesubplottitle

I tried to use this code below to add titles "1" and "2" to my images, but only "1" shows above the first image.
Could anyone help me with this? I want to show "1" above the first image, and "2" above the second.
Thanks in advance.
subplot(1,2,1),imshow(I1),title('1');hold on
subplot(1,2,2),imshow(I2),title('2');hold off

Best Answer

What you want to happen is actually what DOES happen:
I1 = imread('cameraman.tif');
I2 = imread('moon.tif');
subplot(1,2,1),imshow(I1),title('1');hold on
subplot(1,2,2),imshow(I2),title('2');hold off
0000 Screenshot.png
If you want, you can explicitly put the axes handle in:
h1 = subplot(1,2,1), imshow(I1, 'Parent', h1), title(h1, '1'); hold on
h2 = subplot(1,2,2), imshow(I2, 'Parent', h2), title(h2, '2'); hold off