This is to show an alternative for matlab code with highlighting.
It is better to use mcode to typeset the matlab codes. mcode internally uses listings package and offers features like different colored text etc.
An example:
\documentclass{article}
% load package with ``framed'' and ``numbered'' option.
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\lstset{
rulecolor=\color{black}
}
% something NOT relevant to the usage of the package.
\setlength{\parindent}{0pt}
\setlength{\parskip}{18pt}
\begin{document}
The following demo block shows some matlab code:
\begin{lstlisting}
for i = 1:3
if i >= 5 % literate programming replacement some thing to fill in the space
disp('cool'); % comment with some §\mcommentfont\LaTeX\ in it: $\mcommentfont\pi x^2$§
end
really really long really really long really really long really really long really really long line % blaaaaaaaa
end
\end{lstlisting}
\end{document}


You can add captions by using
\begin{lstlisting}[caption=My code here]
\documentclass{...}and ending with\end{document}. – jub0bs Apr 29 '13 at 11:30\usepackagedoesn't work inside the document. – Marco Daniel Apr 29 '13 at 11:33skipabove=\topsep,skipbelow=\topsep(for instance) to yourmdframedenvironment. – jub0bs Apr 29 '13 at 11:34matlab-prettifierpackage; see this answer of mine. – jub0bs Feb 10 '14 at 13:20