MATLAB: Keep tight borders in image and still keep the title when saving

figureMATLABpaperpositionsaveastighttitle

I have quite a lot of 224×289 images that I want to save. I want to avoid wasting space with borders. Preferably the resulting images should all have the same size including their colorbar + colorbar title + figure title. Here is the code
figure(1);
imshow(image,range);
title('title');
c = colorbar;
c.Label.String = 'Gray value';
I tried saving with
iptsetpref('ImshowBorder','tight')
saveas(gcf,'name.png')
but it cuts away the title.
When saving with
set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperPosition', [0 0 15 10]); %x_width=10cm y_width=15cm
saveas(gcf,'fig1.tif')
I tried to find reasonable values for width etc but I cannot for the life of me get the figure to show the colorbar with title AND the figure's title. Something always gets cut.
Can someone tell me how I could set my image size by hand or cut the image so that the margins are outside of my title and colorbar title?

Best Answer

Use latest version of export_fig . Attached are two images. One is saved with export_fig and one with saveas.
A = imread('cameraman.tif');
imshow(A)
title('title');
c = colorbar;
c.Label.String = 'Gray value';
iptsetpref('ImshowBorder','tight')
%%Save
export_fig(1,'-jpeg','untitled_1')
saveas(1,'untitled_2.jpg')
Turns out export_fig crops the image by default, exactly as you requested.