For my Master thesis I was writing a lot of code in MatLab. In order to have it "pretty printed" I used the same package as @cmhughes mentioned. It looks like this (at the preamble):
\usepackage{listings} %For code in appendix
\lstset
{ %Formatting for code in appendix
language=Matlab,
basicstyle=\footnotesize,
numbers=left,
stepnumber=1,
showstringspaces=false,
tabsize=1,
breaklines=true,
breakatwhitespace=false,
}
Then, when you want to include your code file, just use \lstinputlisting. Continuing with the example:
\lstinputlisting[language=Matlab]{./Code/calc_error.m}
I particularly loved this because it allowed me to change my code in MatLab in the folder itself and I didn't have to update it in LaTeX, since I was pointing directly to the file and not the code per se.
The result will be something like this:

Of course, you can always play with \lstset in order to get what you want, as explained in the documentation
\usepackage{listings}and then\begin{lstlisting}your code here \end{lstlisting}.texdoc listingsfor more info – cmhughes Apr 03 '13 at 21:33matlab-prettifierpackage; see this answer. – jub0bs Apr 28 '14 at 15:43