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}
.\usepackage
doesn't work inside the document.skipabove=\topsep,skipbelow=\topsep
(for instance) to yourmdframed
environment.matlab-prettifier
package; see this answer of mine.