As @LewisNorton explained, you need to set the Paper***
properties of the figure. Below is an example for producing a PDF file with dimensions 420 x 297 mm
(A3 size), where the margins between the plot and the file borders are 10 mm
each (top,bottom,left,right).
%
X = 42.0; %
Y = 29.7; %
xMargin = 1; %
yMargin = 1; %
xSize = X - 2*xMargin; %
ySize = Y - 2*yMargin; %
%
hFig = figure('Menubar','none');
plot([0 1 nan 0 1], [0 1 nan 1 0]), axis tight
set(gca, 'XTickLabel',[], 'YTickLabel',[], ...
'Units','normalized', 'Position',[0 0 1 1])
%
set(hFig, 'Units','centimeters', 'Position',[0 0 xSize ySize]/2)
movegui(hFig, 'center')
%
set(hFig, 'PaperUnits','centimeters')
set(hFig, 'PaperSize',[X Y])
set(hFig, 'PaperPosition',[xMargin yMargin xSize ySize])
set(hFig, 'PaperOrientation','portrait')
%
print -dpdf -r0 out.pdf
winopen out.pdf


Without a printer at hand, I am using a virtual screen ruler to check the measurements; Simply display the PDF file with your preferred viewer, and the set the zoom level at 100% (I am using Sumatra PDF). If you want to try this yourself, just be aware that some viewers (Adobe Reader) might be using a custom DPI not matching the system default resolution (mine at 96 pixels/inch).
Here you can see the bottom and left margins equal to 10mm
. The same holds for the other two margins:

Note that in the example above, I made the axis cover the entire figure (no gray area in the figure). By default, MATLAB leaves some empty space for tick labels, axis labels, title, etc.. This is of course different from the margins mentioned above, which I assume you already know :)