Computational Economics

computational tools for economists

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s