matlabfrag user guide Zebb Prime May 4, 2010 Contents 1 Introduction 2 2 Backgr

matlabfrag user guide Zebb Prime May 4, 2010 Contents 1 Introduction 2 2 Background 2 3 Compared to LaPrint 3 4 Usage 4 4.1 Within Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.2 Within LaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.3 Within pdfLaTeX . . . . . . . . . . . . . . . . . . . . . . . . . 7 4.4 Within LyX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5 Creating figures in Matlab 8 5.1 Sizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.3 FontSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.4 FontAngle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5.5 FontWeight . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5.6 FontName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.7 Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.8 Multi-line text . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.9 Custom tick labels . . . . . . . . . . . . . . . . . . . . . . . . 13 5.10 Legends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.11 Tick scaling values . . . . . . . . . . . . . . . . . . . . . . . . 14 6 Frequently (occasionally) asked questions 16 6.1 Why does the output have three digit numbers all through it? 16 6.2 Why doesn’t the .tex file have the includegraphics state- ment in it like LaPrint does? . . . . . . . . . . . . . . . . . . . 16 1 7 Troubleshooting 16 7.1 I get an error in Matlab! . . . . . . . . . . . . . . . . . . . . 16 7.2 I get a warning in Matlab! . . . . . . . . . . . . . . . . . . . 17 7.3 I get the Unable to interpret TeX string warning in Mat- lab! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 7.4 My graphic exports from Matlab fine, but does not compile in LaTeX/pdfLaTeX/LyX! . . . . . . . . . . . . . . . . . . . . 18 7.5 My graphic exports from Matlab and compiles in LaTeX/ pdfLaTeX/LyX but doesn’t look right! . . . . . . . . . . . . . 18 8 Advanced usage: a discussion on renderers 19 9 Advanced usage: a discussion on axis ticks 21 1 Introduction matlabfrag is a function which exports a Matlab figure to .eps and .tex files for use in LaTeX with psfrag. It is inspired by LaPrint, but is intended to be more WYSIWYG, by respecting figure handles better. The main reasons to use matlabfrag are the same as those for using psfrag: figure font matching that of the document, and the ability to have complex mathematical expressions typeset by LaTeX. 2 Background I wrote matlabfrag after becoming frustrated with the default LaPrint behaviour, including it putting the line to insert the graphic in the output .tex file: \includegraphics{FileName.eps} Whilst these problems could be addressed using one of the many options in LaPrint, I decided to take a stand against the many Matlab scripts and functions available which try to impose their own sense of style on my figures, and instead write a function which does everything possible to respect the figure handles. Everyone has their own sense of style, for better or worse, and I’m sure most users have their own little scripts set up to format their figures in their own way. The problem I have with the \includegraphics{FileName.eps} line in the .tex file is that I keep my figures in a graphics subdirectory of my main document. This meant I had to manually edit the .tex file every time I exported the figure from Matlab. 2 3 Compared to LaPrint In this section I compare the output from LaPrint and matlabfrag for an identical figure. I have chosen some examples that shows some of the weaknesses of LaPrint, so be sure to take these comparisons with a grain of salt. The code for the first comparison is given in examples/comparison01.m and the results are shown in Figure 1. Notice that the legend box for the LaPrint output has been shrunk, and is too small for the equation, and the y axis scale has disappeared. I am unwilling to blame LaPrint for the equation not rendering as it may by a bug in any stage of the fairly complicated conversion process (which has nothing to do with matlabfrag). The output .tex and .eps files appear to have the text conversion set up properly. f (x) = ae−(x−b)2 2c2 −5 0 5 ×10−3 0 0.2 0.4 0.6 0.8 1 (a) graphics/comparison01- matlabfrag s09 -5 0 5 0 0.2 0.4 0.6 0.8 1 (b) graphics/comparison01-laprint Figure 1: matlabfrag output versus LaPrint output for a simple graph. Notice the legend box for the LaPrint is incorrectly sized, and the y axis scale has disappeared. I am unsure why the equation is not rendering in the LaPrint version, and it is unlikely to be the fault of LaPrint. In this second comparison a scaled version of the Matlab peaks func- tion is presented. The Matlab code for this example is given in: examples/comparison02.m and the results are shown in Figure 2. The axis labels are handled better by matlabfrag and it also manages to reproduce the x and y axis scales, but I stress that they only work well for the default orientation of a surf plot. If you start rotating the image they are unlikely to come out correctly. This is 3 discussed further in Section 9. z axis y axis x axis ×10−3 −5 0 5 ×10−3 −5 0 5 ×10−3 −1 −0.5 0 0.5 1 (a) graphics/comparison02-matlabfrag x axis y axis z axis -5 0 5 -5 0 5 -1 -0.5 0 0.5 1 ×10−3 (b) graphics/comparison02-laprint Figure 2: matlabfrag output versus LaPrint. 4 Usage 4.1 Within Matlab Using matlabfrag within Matlab is easy. Simply format the figure how you like it, then run matlabfrag. The format for the matlabfrag command is: matlabfrag(FileName,OPTIONS) where FileName (required) is the file name for the output .tex and .eps files, and OPTIONS are key-value pairs for the optional options: 'handle' The handle for the figure to export. The default is gcf (‘get current figure’). 'epspad' The number of points to pad the output .eps file by. The default is [0,0,0,0]. 'renderer' The output renderer. The default is painters. The renderer is dis- cussed in more detail in Section 8. 4 'dpi' The output resolution (DPI or more appropriately, PPI) of the figure. For the painters renderer this defaults to 3200, and when using the opengl or zbuffer renderers the default is 300. A discussion of renderers is given in Section 8. Some examples are given below. hfig = figure(gcf); plot(rand(2)); axis([1 2 0 1]); matlabfrag('graphics/ex01-1'); matlabfrag('graphics/ex01-2','epspad',[10,10,10,10],... 'handle',hfig); See Figure 3 for the output. 1 1.5 2 0 uploads/Litterature/ user-guide-matlab.pdf

  • 34
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager