# How to convert a matlab figure to a latex code? (not to a graphic)

First of all sorry for my bad english. I want to convert my matlab figure to a latex code (no graphic). I want the latex code. I know its possible. But i dont know how. Of course i can also export my matlab figure to an eps or pdf! But i need from this matlab figure the latex code. i hope you understand my problem. thank you in advance.

It is highly recommended to use matlab2tikz for this task. You need to download the package and after plotting your figure in Matlab, you should run the matlab2tikz.m function by:

matlab2tikz('YourLatexFile.tex');


Then you can add YourLatexFile.tex into your LaTeX source code, for example by using \input{YourLatexFile.tex}:

\documentclass{article}

\usepackage{pgfplots}
%% the following commands are sometimes needed
\usetikzlibrary{plotmarks}
\usepackage{grffile}
\usepackage{amsmath}
%% you may also want the following commands
%\pgfplotsset{plot coordinates/math parser=false}
%\newlength\figureheight
%\newlength\figurewidth

\begin{document}
\input{YourLatexFile.tex}
\end{document}


Also there are suitable documentation and examples in their Github page.