MATLAB: How to reduce the margins around an image I am printing to eps in MATLAB 7.6 (R2008a)

MATLAB

I want to reduce the margins around an image I am printing to eps.
Reproduction code:
surf(peaks)
set(gcf,'OuterPosition',[200 200 400 440]);
axis square
print -depsc -tiff -r300 testfigure
Import testfigure.eps in a Word Document and click on it to see the borders of the image. I would like those borders to be tight around the image. Instead, I see a white margin to the left and right of the image.

Best Answer

To reduce the margins around an image, you can set the width and the height of the Paper Position property. This can be done using the Export Setup GUI found under File->Export Setup in the Figure Window. Or, it can be done programmatically using the SET command as shown in the following example code, which sets the width and height to be 4x4 inches:
surf(peaks)
set(gcf,'OuterPosition',[200 200 400 440]);
axis square
pos = get(gcf,'paperposition');
set(gcf,'paperposition',[pos(1),pos(2), 4, 4]);
print -depsc -tiff -r300 testfigure