MATLAB: Am I unable to save a figure as a full page PDF-file in MATLAB

MATLAB

When I save my figure to a PDF file, there is no option to make it fill the page, as there is when I print it. For example,
figure
plot(rand(100 ,2))
Then I use the "File->Save As" menu option and select the PDF file type.

Best Answer

The ability to save a figure as a PDF-file which fills the page is not available in MATLAB.
To work around this issue, you can change the size of the figure and then save it to a PDF-file.
For example, the following code sets the size of the figure to 8.5-by-11 inches:
figure
plot(rand(100 ,2))
set(gcf,'units','inches')
old_pos = get(gcf,'position'); % save current "position" to be restored later
set(gcf,'Position',[0 0 8.5 11])
Then save the file in a PDF format using the "File->Save As" menu option.
You can restore the figure back to its original size using the "old_pos" variable:
set(gcf,'position', old_pos)