Computational Economics

computational tools for economists

Archive for October 2012

Insert matlab code into LaTex

leave a comment »

  1. Download “M-code LaTeX Package” from Mathworks webpage
  2. Copy mcode.style to the folder C:\Program Files\MiKTeX 2.9\tex\latex\xcolor.
  3. 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}

Advertisements

Written by Jingjing Wang

10/23/2012 at 11:14 am

Posted in LyX