Importing MATLAB Figures into Latex

79 vues (au cours des 30 derniers jours)
Yellow Canary
Yellow Canary le 18 Jan 2015
I have a Matlab figure and I want to import it to latex. My code is
>> plot3(Pa,Pb,Profit,'x') >> print -deps graph1
Then I copy and paste the eps file to my latex file and use this code.
\begin{figure}
\centering
\includegraphics{graph1}
\caption{}
\end{figure}
Error: Unknown graphics extension.
Does anyone know how to import Matlab figures into Latex?
Thanks
  2 commentaires
marcflight
marcflight le 21 Sep 2015
Did you add \usepackage{graphicx} in the preamble ? Did you move the graph1 image to your LaTeX directory?
Sanket Bhagat
Sanket Bhagat le 11 Oct 2017
still same problem sir?? what to do?

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 19 Jan 2015
You are probably not actually compiling using LaTeX, but more likely you are using pdfLaTeX, which is much more commonly used these days to create PDF's directly from the .tex files. True LaTeX (like TeX that it is based on) creates .dvi files, not PDF's.
This difference is important as the different compilation engines support different image formats. The best way is to check the documentation for the exact compilation engine that you are using. In the case of pdfLaTeX compilation (the most popular today), EPS files are not supported.
The WikiBooks website is a good source of info on LaTeX:
https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics
In particular, it says this:
Compiling with latex
  • The only format you can include while compiling with latex is Encapsulated PostScript (EPS).
Compiling with pdflatex
If you are compiling with pdflatex to produce a PDF, you have a wider choice. You can insert:
  • JPG, widely used on Internet, digital cameras, etc. They are the best choice if you want to insert photos.
  • PNG, a very common format (even if not as much as JPG); it's a lossless format and it's the best choice for diagrams (if you were not able to generate a vector version) and screenshots.
  • PDF, it is widely used for documents but can be used to store images as well. It supports both vector and bit-map images, but it's not recommended for the latter, as JPG or PNG will provide the same result using less disk space.
It goes on to give state that you can use EPS with pdfLaTeX, but only with the help of some other tools or some intermediate processing
  • EPS can be used with the help of the epstopdf package.
The WikiBooks website will give a good intro on how to do this.

Plus de réponses (2)

Chad Greene
Chad Greene le 18 Jan 2015
Instead of print I tend to use export_fig to export a very nice looking pdf. \includgraphics handles pdfs well.
  3 commentaires
Yellow Canary
Yellow Canary le 19 Jan 2015
I also tried to import the figure as pdf and get this error: ! LaTeX Error: Unknown graphics extension: .1.See the LaTeX manual or LaTeX Companion for explanation.Type H return for immediate help.... \includegraphics{f1.1}
Chad Greene
Chad Greene le 19 Jan 2015
I am guessing you put export_fig somewhere that Matlab can't find it. And pdfs in LaTeX should be no problem with \usepackage{graphicx} in the header.

Connectez-vous pour commenter.


Youssef  Khmou
Youssef Khmou le 19 Jan 2015
Besides the explained proposition above, try to specify the extension in the source File :
\usepackage{graphicx}
\usepackage{epstopdf}
% other Tex instructions {Document ....}
\begin{figure}
\centering
\includegraphics{graph1.eps}
\caption{....}
\end{figure}
  1 commentaire
Muhammad Salman Bashir
Muhammad Salman Bashir le 5 Déc 2019
but my graph shape is black i want it in colours these graph..is this possible with these graphs????

Connectez-vous pour commenter.

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by