Code:

% Binomial method for a European put.
%
% Uses explicit solution based on binomial expansion.
% Vectorized and based on logs to avoid overflow.
%%%%%%%%%% Problem and method parameters %%%%%%%%%%%%%
SavedResults=[];
for M = 1:100
S = 5;E = 10;T = 1;r = 0.06;sigma = 0.3;
dt = T/M;h = 1;
u = exp(sigma*dt^0.5)+h*sigma^2*dt;d = 1/u;p = (exp(r*dt)-d)/(u-d);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Option values at time T
W = max(E-S*d.^([M:-1:0]').*u.^([0:M]'),0);
% log/cumsum version
csl = cumsum(log([1;[1:M]']));
tmp = csl(M+1) - csl - csl(M+1:-1:1) + log(p)*([0:M]') + log(1-p)*([M:-1:0]');
value = exp(-r*T)*sum(exp(tmp).*W);
disp('Option value is'), disp(value)
SavedResults=[SavedResults,value];
end

and the array SavedResults should contain all the results.

CB