I would use mcode from Matlabcentral for this purpose since it is customized for matlab.
Say, the contents of ff16.m is like this:
%%
%Initialization
clear all
clc
for f=1:20
p=2; % dimension of search space
s=26; % The number of bacteria
Nc=36; % Number of chemotactic steps
Ns=20; % Limits the length of a swim
Nre=4; % The number of reproduction steps
Ned=2; % The number of elimination-dispersal events
Sr=s/2; % The number of bacteria reproductions (splits) per generation
Ped=0.25; % The probabilty that each bacteria will be eliminated/dispersed
c(:,1)=0.005*ones(s,1); % the run length
for m=1:s % the initital posistions
P(1,:,1,1,1)=0+rand(1,s)*(1-(0))';
P(2,:,1,1,1)=0+rand(1,s)*(1-(0))';
%P(3,:,1,1,1)= .2*rand(s,1)';
end
Now I want to insert this code in my tex file and I do not want to type or copy/paste it again. This is how it can be done provided ff16.m, my main.tex file and mcode.sty are all in the same folder:
\documentclass{article}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\begin{document}
\begin{figure}
\caption{My program}
\lstinputlisting{ff16.m}
\end{figure}
\end{document}
The result will be:

Without figure environment, the code will have a box. Since you wanted to float this code like a figure, I have just used figure environment and every thing (that should work for a figure like a caption) should work as expected.
Better way to present a code would be:
\documentclass{article}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\begin{document}
%\begin{figure}
%\caption{My program}
\lstinputlisting[caption=My code here]{ff16.m} % note the caption here.
%\end{figure}
\end{document}
Advantage here is the caption will read Listing 1: My code here instead of Figure 1:.... (You can change Listing 1: by \renewcommand{\lstlistingname}{My program} to get My program 1:)

Also, note that the long comments are wrapped automatically at the end of the line.
For details, refer to the mcode.sty file itself, from the above link (matlab central).