Attach MATLAB Graphs to Latex File

  • MATLAB
  • Thread starter sara_87
  • Start date
  • Tags
    Latex
In summary, you can attach a MATLAB graph to a Latex file by using the "Scalable Vector Graphics (SVG) Export of Figures" from MATLAB Central, saving the figure as a PDF, and then exporting the PDF as a Latex file.
  • #1
sara_87
763
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
  • #2
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}
 
  • #3
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
 
  • #4
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:
  • #5
for your question. Yes, there is a way to attach MATLAB graphs directly onto a LaTeX file without having to copy and paste it onto another program. You can do this by using the "exportgraphics" function in MATLAB, which allows you to save your graph directly as a .eps, .pdf, or .svg file. Then, in your LaTeX file, you can use the "includegraphics" command to insert the saved graph into your document. This will ensure that the graph maintains its quality and clarity in your LaTeX file. Additionally, you can also use the "saveas" function in MATLAB to save your graph as a .fig file, which can then be opened and edited in MATLAB at a later time if needed. I hope this helps. Good luck with your work!
 

Related to Attach MATLAB Graphs to Latex File

1. What is the easiest way to attach MATLAB graphs to a LaTeX file?

The easiest way to attach MATLAB graphs to a LaTeX file is by using the "saveas" function in MATLAB. This function allows you to save your MATLAB graph as an image file (such as .jpg or .png) which can then be easily inserted into your LaTeX document.

2. How do I adjust the size of my MATLAB graph in LaTeX?

To adjust the size of your MATLAB graph in LaTeX, you can use the "width" or "height" options when inserting the image into your document. For example, \includegraphics[width=0.5\textwidth]{graph.jpg} will insert the graph at 50% of the width of the text. You can also use the "scale" option to adjust the size proportionally.

3. Can I add labels and legends to my MATLAB graph in LaTeX?

Yes, you can add labels and legends to your MATLAB graph in LaTeX. You can use the "xlabel", "ylabel", and "legend" functions in MATLAB to add labels and legends to your graph before saving it as an image and inserting it into your LaTeX document.

4. How can I ensure that my MATLAB graph is in high quality when inserted into LaTeX?

To ensure that your MATLAB graph is in high quality when inserted into LaTeX, you can save the graph as a vector image (such as .eps or .svg) instead of a raster image (such as .jpg or .png). Vector images are scalable and will maintain their quality when resized in LaTeX.

5. Is it possible to update my MATLAB graph in LaTeX if I make changes to it?

Yes, it is possible to update your MATLAB graph in LaTeX if you make changes to it. You can simply overwrite the previously saved image file with the updated version and recompile your LaTeX document to see the changes. Alternatively, you can use the "matlab2tikz" function in MATLAB to directly generate a LaTeX code for your graph, which can be easily updated with any changes made in MATLAB.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
23
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
20
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
962
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top