Archive for October 2012
Insert matlab code into LaTex
- Download “M-code LaTeX Package” from Mathworks webpage
- Copy mcode.style to the folder C:\Program Files\MiKTeX 2.9\tex\latex\xcolor.
- Add the following in the preamble:\usepackage{listings}
\usepackage{xcolor}
\usepackage{textcomp}
\usepackage[numbered,framed]{mcode}
In LyX, insert a TeX code box.
Insert m-code inline: \mcode{for i=1:3, disp(‘cool’); end;}
Insert m-code blocks: (% it’s a mess when copy and paste. prefer the 3rd approach)
\begin{lstlisting}
% Plot expected state and policy path
a = [a; c(:)’];
r = a’;
\end{lstlisting}
Insert a m-code file:
\lstinputlisting[firstline=110, lastline=117]{/weed.m}