# Tag Info

81

Here is the template I use for matlab code: \documentclass{article} \usepackage{listings} \usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white \definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue \definecolor{mylilas}{RGB}{170,55,241} \begin{document} \lstset{language=Matlab,% %basicstyle=\color{red}, ...

78

For typesetting Matlab code in LaTeX, consider using the matlab-prettifier package. Piggybacking on the listings package, it doesn't require much configuration, and it keeps track of the context (behind the scenes) in order to highlight code as it appears in the Matlab editor. In this respect, it arguably does a much better job than the other available ...

51

I managed to achieve a 3-dimensional histogram effect by repeating the coordinates. I just repeat each x,y combination 4 times, once for each of the 4 possible bar tops it could appear in. For example, the code \documentclass{minimal} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ view = {120}{35},% important to draw x,y ...

39

Some updates on using plot2svg in MATLAB R2014b as of Mar 2015: Jürg hasn't updated his awesome script for a while. For those of you who got an error while using plot2svg in R2014b, the simplest solution is just changing every str2num function in the original plot2svg to str2double, and problem solved. (Original post) matlab2tikz is the best vector graphics ...

34

The mcode package still supports Matlab code formatting, setting the default lstlisting environment (from listings) formatting to that of Matlab. It also provides \mcode{<code>} for inline Matlab code. \documentclass{article} % http://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package \usepackage[framed,numbered,autolinebreaks,...

27

You'll find a listings language definition for the Julia language in the code below. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{beramono} \usepackage{listings} \usepackage[usenames,dvipsnames]{xcolor} %% %% Julia definition (c) 2014 Jubobs %% \lstdefinelanguage{Julia}% {morekeywords={abstract,break,case,catch,const,continue,do,else,...

23

matlab2tikz now fully supports 3D histograms. This load seamount dat = [-y,x]; % Grid corrected for negative y-values hist3(dat) % Draw histogram in 2D n = hist3(dat); % Extract histogram data; % default to 10x10 bins view([-37.5, 30]); gives

20

Since I didn't have any luck with altering the TeX memory capacity, I had to find another way to solve my problem. It was matlab2tikz that actually did the job. It has an option of downsampling the figures during the conversion to tikz-pgf. It is called minimumPointsDistance. The final (downsampled) figures where absolutely indistinguishable from the ...

17

when plotting in Matlab, set the text interpreter to be latex: Figure1=figure(1);clf; set(Figure1,'defaulttextinterpreter','latex'); plot(...); xlabel('$\delta$'); ylabel('$\epsilon$');

14

I use gnuplot sum function combined with the tikz key raw gnuplot that allows the user to give from tikz/pgfplots the raw commands gnuplot will execute. \documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel = $t$, xtick = {-.5,.5}, xticklabels = {$-\frac{T}{2}$, \$\...

13

Another approach would be to modify the MATLAB style to produce the text you want. The default style sheet for LaTeX mxdom2latex.xsl (in R2011a it is located in ...toolbox/matlab/codetools/private/) has the following section <xsl:template match="p">\begin{par} <xsl:apply-templates/><xsl:text> \end{par} \vspace{1em} </xsl:text> </...

13

No idea if this could be done "natively" with asymptote, pstricks or TikZ, or even by calculating all the data in an external program and then plotting it with pgfplots. I went for doing everything in python and simply including the resulting image. This adapts the python code written by Alex J. DeCaria, taken from the ipython notebook linked on this page. ...

12

Yes, pgfplots can do it: you can provide color data explicitly. I suppose the most simple way is to provide a combined table with columns x y z c and to tell pgfplots to read point meta data which is given explicitly point meta=explicit to configure from where explicit color data should be read \addplot .. table[meta=c] . You can generate such data ...

12

With Asymptote it is possible to draw a 3D vector field along a surface (not a path). It is not difficult to adapt this routine to draw a 3D vector field along a path. However the sophisticated arrow is not availabe and needs more work. Please find a example import graph3; size(200,0); currentprojection=perspective(10,8,4); real f(pair z) {return 0.5+...

11

I was not satisfied with the previous answers and therefore created my own solution. Jake's solution is present in the documentation but first I couldn't make it work, second it does not generate a image from data, which is what I want from Tikz. I worked on Anton's answer. It took me some time to figure out the way coordinates were organized to put it in a ...

11

Updated answer -- standalone (Note: I haven't tested this updated part of the answer, with the standalone option. Will remove this message when I have.) matlab2tikz has an option standalone that generates a complete, compilable file with the standalone documentclass. Hence, by doing matlab2tikz('test.tikz','standalone',true) the resulting file can be ...

11

Here's my manual approach to untangling and manually wrapping the code: \documentclass{article} \usepackage{showframe} \usepackage{listings} \begin{document} \begin{lstlisting}[language=Matlab,gobble=8] a = x1*R_o2*t_st/v_ca; b = x3*R_n2*t_st/v_ca; c = x1*R_o2+x3*R_n2+x8*R_v; d = x5*phi_atm*p_sat_t_atm/(p_atm*p_sat_t_cl)*...

10

I can't quite see what matlab is doing less latex works than I would expect, however this sort of works to make the first expression larger: So after a bit of trial and error and discussion in comments most of latex is enabled but you need to switch out of math mode, use a lower level font size change such as \fontsize{20}{25}\selectfont for 20pt font, and ...

10

As mentioned in zuggg's comment, you can convert MATLAB figures to TikZ by using the matlab2tikz script. What this does is collect the data points and then uses the PGFPlots \addplot table to recreate the plot. The author wrote the script so that it also works in GNU Octave, but the MATLAB Central license does not allow use of the shared software in non-...

10

Short answer: don't use algorithm for typesetting source code. Use either the listings or minted package instead, or (edit) the matlab-prettifier package; see below. Detailed answer: You can change the way algpseudocode's keywords (such as for, while, etc.) are typeset by redefining them using algorithm's \algdef command. The following modification answers ...

9

The mcode package provides \mcode{<code>} for inline MATLAB code. The following example is taken almost verbatim from the demo documentation: \documentclass{article} % http://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package \usepackage{mcode} \begin{document} This inline demo \mcode{for i=1:3, disp('cool'); end;} uses \verb|\...

9

Background There is no easy way to do this, but there are a 3 ways to hack it. To understand how to control the MATLAB LaTeX interpreter, you need to understand how it works. When MATLAB processes a LaTeX string it calls tex.m. The MATLAB tex function appends \nofiles \documentclass{mwarticle} \begin{document}\setbox0=\hbox{ and prepends }\copy0\special{...

9

scrbook defines a macro \ifnumbered that isn't a TeX if which is not necessarily wrong but it is a bit dangerous and here mcode pushes you over a cliff. You can restore scrbook s definition: \documentclass{scrbook} \let\zz\ifnumbered \usepackage{mcode} \let\ifnumbered\zz \begin{document} %\tracingall \chapter{matlab code} \end{document}

9

Use pst-solides3d. Start from my code to work out your example. Be warned that it takes really a long time to compile. \documentclass{article} \usepackage{etex} \usepackage{pst-solides3d} \newcommand\arrow[2]{ \psSolid[object=cylindre,h=.11,r=.04, fillcolor=#2,linewidth=.25pt, transform={0 0 -.2 translatepoint3d #1},ngrid=1 16] \psSolid[...

8

Export_fig makes all the work automatically, including margins and pdf creation. The original Matlab save result is: export_fig results (picture size is the same) is: Note: this command is improvement of savefig command.

8

In my opinion, it would be simpler and more robust to just use linerange markers for listings in comments of your m-file. See the example below. I used the matlab-prettifier package instead of mcode, but the approach should work with either. Basically, you define a prefix for those linerange markers with the rangeprefix key; here, the prefix I use is simply ...

Only top voted, non community-wiki answers of a minimum length are eligible