Attach MATLAB Graphs to Latex File

  • Context: MATLAB 
  • Thread starter Thread starter sara_87
  • Start date Start date
  • Tags Tags
    Latex
Click For Summary

Discussion Overview

The discussion revolves around methods for attaching MATLAB graphs to a LaTeX file, exploring various approaches and tools available for exporting and integrating graphics into LaTeX documents.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant inquires about attaching MATLAB graphs to LaTeX without using a screenshot method, expressing a desire for a more direct approach.
  • Another participant suggests that MATLAB may export graphs as encapsulated PostScript (EPS) files, providing a code snippet for including such files in LaTeX.
  • A later reply confirms that MATLAB can indeed export graphs as EPS files.
  • Another participant proposes a multi-step method involving exporting figures as SVG files from MATLAB, converting them to PDF using Inkscape, and then including them in LaTeX, detailing each step of the process.
  • This method emphasizes the advantages of SVG files, such as resolution independence, and includes additional LaTeX code examples for scaling and subfigures.

Areas of Agreement / Disagreement

Participants present multiple methods for attaching MATLAB graphs to LaTeX, with no consensus on a single best approach. Some methods involve EPS files, while others focus on SVG to PDF conversion.

Contextual Notes

The discussion includes various assumptions about the capabilities of MATLAB and the tools mentioned, such as Inkscape, and does not resolve potential limitations or dependencies on specific software versions.

sara_87
Messages
748
Reaction score
0

Homework Statement



Is there a way i can attatch MATLAB graphs onto the Latex file?

Homework Equations





The Attempt at a Solution



I copied and pasted it onto paint then saved it as .jpg but i was wondering if there's a way i could attatch the original graph without copying and pasting it onto paint.

Thank you
 
Physics news on Phys.org
I don't use Matlab. Can it export its graphs as encapsulated PostScript files? It it can, then you can do it like this:

\usepackage{graphicx}

\begin{center}
\includegraphics[width=2.5in,height=2.5in]{yourgraph.eps}
\end{center}
 
LCKurtz said:
I don't use Matlab. Can it export its graphs as encapsulated PostScript files? It it can, then you can do it like this:

\usepackage{graphicx}

\begin{center}
\includegraphics[width=2.5in,height=2.5in]{yourgraph.eps}
\end{center}

Yes, it can
 
sara_87 said:

Homework Statement



Is there a way i can attatch MATLAB graphs onto the Latex file?

Homework Equations





The Attempt at a Solution



I copied and pasted it onto paint then saved it as .jpg but i was wondering if there's a way i could attatch the original graph without copying and pasting it onto paint.

Thank you

Sara, here's the magic:

MATLAB > SVG > PDF > Latex

1) You need to download "Scalable Vector Graphics (SVG) Export of Figures" from MATLAB Central.

a. Go to

Code:
http://www.mathworks.com/matlabcentral/fileexchange/7401-scalable-vector-graphics-svg-export-of-figures

b. Extract zip file into the MATLAB folder you will use as a current directory (i.e. where your M-files are located)

c. Simply type "plot2svg" in command window or M-file, a GUI will pop up and ask you where to save the figure as an SVG file. Of course, you need a plot( ) command just before this step to generate a figure!

Note: svgs do not have resolution constraints, like true pdfs.

2) You need inkscape

a. Download: www.inkscape.org/

b. Open the svg file from MATLAB in inkscape

c. shift+ctrl+d: opens document properties, you might want to click fit page to selection - this removes any extra space surrounding the figure.

d. Add any annotations as you wish.

e. shift+ctrl+s: save as... pdf via Cairo

3) Latex

Example of scaled figure (33% of the initial size and lossless!).

Preamble:

Code:
\usepackage{graphics}

Body:

Code:
\begin{figure}[!h]
\centerline{
{\scalebox{0.33}{\includegraphics{figure.pdf}} 
}
\caption{Any caption.}
\label{fig:figlabel}
\end{figure}

You may want to look into the subfloat package for having subfigures (a) (b) (c) ... etc within one plot. Example:

Preamble:

Code:
\usepackage{graphics}
\usepackage{subfig}

Body:

Code:
\begin{figure}[!h]
\centerline{
\subfloat[Vertical cutlines.]%
{\scalebox{0.33}{\includegraphics{NMOS_cutlines.pdf}} \label{fig:nmos1athena2dcut}}
\quad
\subfloat[Doping profile for cutline \# 1.]%
{\scalebox{0.33}{\includegraphics{NMOS_cutlines1.pdf}} \label{fig:nmos1athena2dcut1}} 
\vspace{0.5cm}
}
\centerline{
\subfloat[Doping profile for cutline \# 2.]%
{\scalebox{0.33}{\includegraphics{NMOS_cutlines2.pdf}} \label{fig:nmos1athena2dcut2}}
\quad
\subfloat[Doping profile for cutline \# 3.]
{\scalebox{0.33}{\includegraphics{NMOS_cutlines3.pdf}} \label{fig:nmos1athena2dcut3}} 
\vspace{0.5cm}
}
\caption{NMOSFET doping profile at critical locations.}
\label{fig:nmos2}
\end{figure}

The code looks ugly, but the final result is amazing!

I hope this helps.
 
Last edited:

Similar threads

  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 20 ·
Replies
20
Views
4K
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
8K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K