Typing a long list of Matlab can be tedious and frustrating. A better way is to put the sequence of commands into a file. If you make a file called hw.m in the same directory you are running Matlab from, then typing "hw" to the matlab prompt causes Matlab to do the commands in the hw.m file. For example, if the file contains the lines: n = 20; for i=1:n x(i) = i; y(i) = i*i; end plot(x,y) then typing "hw" to the Matlab prompt will produce a plot of a parabola. Now, if you want to do it again with n=30, just edit that line and type "hw" again. Notice that I indented the two commands "x(i) = i;" and "y(i) = i*i;". These commands form the "body" of the "for loop". Indenting them makes it easier to see at a glance what the program is doing. It is considered "good programming practice". The command "r = randn(1,n);" produces an array with n independent standard normal random variables. You can access the k-th one using r(k). The command "round" rounds a number to the nearest integer. For example, "round(3.4)" gives 3, round(3.6) gives 4, and round(-5.6) gives -6. To figure out which bin R falls into, use "j = round(R/dx);". This will make j the bin. Here , dx is the bin size. The bins have j values from -k to k, including 0. Therefore, the number of bins is NB = 2*k+1. You can find all the bin counts at the same time by first creating an array to record the bin counts NB = 2*k+1; for bin=1:NB count(bin) = 0; end for i=1:n j = round(r(i)/dx); bin = j + k + 1; count(bin) = count(bin) + 1; end In Matlab, all arrays start from index 1. Therefore, we have to number the bin counts starting from count 1, corresponding to bin -k, to count k, corresponding to bin 0, to count 2*k+1, corresponding to bin k. The line "bin = j+k+1;" does this.