If you put all your code in a .m file then instead of printing out what you typed into the Matlab terminal, you can use Matlab's publish option. Using Publish:
There are always things that need to be included in a project submission:
Suppose we were asked to find the LU factorization of some matrices A and B using Matlab.
You could type all your code in the command line, write down what you found for L and U, and copy the codes you used in a text file. Then print out the text file and attach it to your project packet. This is perfectly acceptable, and for those of you with limited computer experience or are feeling like matlab hates you, I would reccomend this approach.
There is another (prefered) option:
You could write a Matlab function that takes in a matrix and then displays the L and U
of the LU factorization and/or you could put all your code into a script file and making sure there are no
semicolons at the ends of the lines, you could publish this script. See below for example:
Suppose you want to write a Matlab function that solves Ux=b for x and only displays x at the end. The following is a test script for such a function, where U is a random matrix and b is built such that all the entries of x will be 1's.