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 to the folder C:\Program Files\MiKTeX 2.9\tex\latex\xcolor.
  3. Add the following in the preamble:\usepackage{listings}

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)

% Plot expected state and policy path
a = [a; c(:)’];
r = a’;

Insert a  m-code file:

\lstinputlisting[firstline=110, lastline=117]{/weed.m}

Written by Jingjing Wang

10/23/2012 at 11:14 am

Posted in LyX