Jonathan Dreyer

Creating Matlab Plots for Thesis

The following instructions assume you have set the LyX font to Latin Modern Roman. This can be done by going to **Settings > Fonts **and selecting *Roman: Latin Modern Roman*.

The matching system font, Computer Modern Unicode, can be downloaded from http://sourceforge.net/projects/cm-unicode/ or as a local download here. Note that although the *Computer Modern Roman* font in LyX looks the same as *Latin Modern Roman*, the later is a vector font and appears clearer in pdfs.

To install these fonts unpack the compressed file (cm-unicode-0.6.3a.zip) into the system fonts directory. On a Window system these are located at \Windows\Fonts\

Example 1

The following example script generates a png file that can be directly imported into LyX without any scaling or modification. Although it appears large in the LyX preview mode, in the generated pdf it will appear at the proper size.

%Example plotting script for generating high resolution Matlab plots %Parameters for saved images a=[0:0.1:100]; figure2 = figure(2); axes1 = axes('FontSize',ImageFontSize,'FontName',AxisFontName); h=plot(a,b,'k',a,c,'k',a,d,'--k'); set(h(1), 'LineWidth',2) xlabel('Frequency (Hz)','fontsize',ImageFontSize) %==================== |

A comparison of the image generated from the default Matlab settings and the modified settings is shown below.

Original Matlab Image |
Modified Matlab Image |

Notes: These images are extremely high DPI; however, anything lower and I have found the images to be blurry. Yes, you could save the images as EPS files and import them into LyX; however, trying to embed the fonts into the EPS is not trivial and I have neither the time nor interest to figure it out. If you know of a way to * easily* do this in Matlab let me know.

Example 2

You will notice that when saving images at higher resolutions Matlab does not scale the dashed lines properly. At high DPI dashed lines become blurry and can appear as solid lines. The following example uses the scripts written by P. Kabal in the Department of Electrical & Computer Engineering at McGill University. This toolkit also adds support for variable dashed-dotted lines. The original material can be found online at: http://www-mmsp.ece.mcgill.ca/Documents/Reports/index.html. I had to modify two functions in this toolkit, the modified version is available here. If you would prefer the original Matlab code it can be downloaded here and the documentation for the m-files is available here (from the McGill web site).

Unpack the MatlabPlot.zip (from this site) or Matlab-Plot-v1r3.tar.gz (from the McGill site) and add it to your Matlab path using the Path Tool GUI. This can be accessed by typing 'pathtool' at the Matlab command window.

The following example uses these functions to create a plot with a variety of dashed and dotted lines that properly scale with increasing image DPI. Additional examples can be found in the Matlab-Plot-v1r3 documentation.

%Example plotting script for generating high resolution Matlab plots %Parameters for saved images %=============== figure2=figure(2); %Set the axis limits prior to calling DashLine axis([min(t) max(t) -1 1]); %Combine data for plot into two arrays %Create the dashed lines %Plot the data %Legend entries %Set Axis Font and Size %==================== |

Output Image

(c) jdreyer 2012