Saving figures
This section is a diversion from introductory material but it generates SO MANY problems I am sick of it!
Getting Matlab figures from the screen in to your document can be done many ways - most of which cause problems. My advice is to start with the following script. You can use it without understanding it too deeply, but as you learn more you will be able to customise it to your own requirements.
The script saves the current figure, in the specified format, at the specified size, without any white space around the edge, and without scaling the fonts. What you get on the screen is more or less exactly what you get in the file. This makes the whole process a doddle once you get used to it.
%
% -----------------------------------------
% fancy export routine designed to
% save your figures exactly how you
% want them to be
%
% this script works for the current figure
% which is the one you last created, edited,
% or just clicked on
% -----------------------------------------
% starts here with the basics
% screenSize is approximate
% figSize 10cm by 7.4cm is about right
% for an A4 page and golden ratio
% works for 4 picture formats
% choose between pdf, png, jpeg, bmp
figSize = [12.0 7.4];
screenSize = [37 30];
fileFormat = 'pdf';
fileName = 'latest_figure';
% every figure has a handle which we have to
% get - there is a function for this called gcf
figHandle = gcf;
% first we set the size units of the figure to
% something familiar
set(figHandle,'PaperUnits', 'centimeters');
set(figHandle,'Units', 'centimeters');
% now sort the size and position out
set(figHandle,'PaperSize', figSize .* 1.1);
set(figHandle,'PaperPositionMode', 'auto');
set(figHandle,'Position', [screenSize/2-figSize/2 figSize]);
% finally print the picture to a file
print(figHandle, ['-d' fileFormat], [fileName '.' fileFormat]);
% the end