Thursday, 6 March 2008

Movies in Matlab

This script shows the very basics on how to generate a movie in Matlab

% Generate a simple movie: plot f(t, x) = sin(x - t) on (0, 2pi) for different t

for i = 1:25

% Make a figure
t = 0.1 * i;
fplot(@(x) sin(x - t), [0 2*pi])

% Store the figure as a frame in the movie


% Play the movie ten times

Friday, 1 February 2008

Change Matlab-figures for print

If you use Matlab to generate EPS-files for inclusion in LaTeX-documents, you'll soon find that lines are too thin and text is too small. I use the following script to increase thickness and size in the current figure in Matlab:
linewidth = 2;
fontsize = 16;
fig = gcf;
h = findall(fig, 'Type', 'Text');
set(h, 'FontSize', fontsize)
h = findall(fig, 'Type', 'Axes');
set(h, 'FontSize', fontsize)
h = findall(fig, 'Type', 'Line');
set(h, 'LineWidth', linewidth)

Source code in LaTeX

If you want to include source code in LaTeX, you can of course use the standard verbatim environment. There are however many advantages to refer to the actual source file on disk instead of copying its contents into your LaTeX document. Referring to a file on disk can be achieved by using the moreverb package.

I use the following commands:
to include the package and to set the amount of white space for tab characters to 4 (default is 8). Next define
to have a new command for including e.g. Matlab scripts. Use it as
to have the file cp19.m in your document.