The updater in matlab2tikz 0.6.0 (and older) no longer works.Please update manually if you are not using matlab2tikz 1.0.0 or newer!
matlab2tikz
is a MATLAB(R) script to convert native MATLAB(R) figures to TikZ/Pgfplots figures that integrate seamlessly in LaTeX documents.
To download the official releases and rate matlab2tikz
, please visit its page on FileExchange.
matlab2tikz
converts most MATLAB(R) figures, including 2D and 3D plots.For plots constructed with third-party packages, however, your mileage may vary.
src/
folder to your path in MATLAB/Octave: e.g.
addpath
function from your command window or startup
script.Make sure that your LaTeX installation is up-to-date and includes:
It is recommended to use the latest stable version of these packages.Older versions may work depending on the actual MATLAB(R) figure you are converting.
Typical usage of matlab2tikz
consists of converting your MATLAB plot to a TikZ/LaTeX file and then running a LaTeX compiler to produce your document.
Generate your plot in MATLAB(R).
Run matlab2tikz
, e.g. using
matlab2tikz('myfile.tex');
Add the contents of myfile.tex
into your LaTeX source code, for example using \input{myfile.tex}
.Make sure that the required packages (such as pgfplots
) are loaded in the preamble of your document as in the example:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%% the following commands are needed for some matlab2tikz features
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{grffile}
\usepackage{amsmath}
%% you may also want the following commands
%\pgfplotsset{plot coordinates/math parser=false}
%\newlength\figureheight
%\newlength\figurewidth
\begin{document}
\input{myfile.tex}
\end{document}
Most functions accept numerous options; you can check them out by inspecting their help:
help matlab2tikz
Sometimes, MATLAB(R) plots contain some features that impede conversion to LaTeX; e.g. points that are far outside of the actual bounding box.You can invoke the cleanfigure
function to remove such unwanted entities before calling matlab2tikz
:
cleanfigure;
matlab2tikz('myfile.tex');
matlab2tikz
, have a look at our GitHub repository. If you are a good MATLAB(R) programmer or LaTeX writer, you are always welcome to help improving matlab2tikz
!最近在学matlab和latex,记录一下自己matlab2tikz入门的心得。 下载matlab2tikz 这里是matlab2tikz的GitHub地址 把它完整下载到本地。 下载完成后,将下载获得的文件夹中的\src文件夹添加到matlab路径中。 进入matlab,在matlab绘图结束后,在command window键入以下指令:matlab2tikz('myfile.tex');这样
到目前为止, matlab2tikz还不支持所有MATLAB图形的转换. 比如对于3维点图和线图就不支持. 如果你有一个漂亮的二维图形, matlab2tikz支持得很好. matlab2tikz 支持功能完全涵盖它的前任matfig2pgf. 支持的特征有(不限于): * 绝大多数 axes 属性 (包括对数坐标), * 网格, * 线图 (包括标记, 线的样式), * 等高线图(包括填充的)
This is matlab2tikz, a MATLAB(R) script for converting MATLAB figures into native TikZ/Pgfplots figures. matlab2tikz supports the conversion of most MATLAB figures, including 2D and 3D plots. For plot