MATLAB: How to sum results of simulations from the command window

resultssum

I've created a code that does 100 simulations, producing either a 0 or a 1 as the result. I want to be able to add up all the '1s' to find a probability. Every attempt I've made to do this using the sum function has come up with nothing. This is the code:
for c =1:100
n = NumberOfCustomersToBeServed;
x = rand(1,n);
W = zeros(size(x));
for ii=1:length(x)
if x(ii) <= 0.2
W(ii) = 0;
elseif x(ii) > 0.2 & x(ii) < 0.4
W(ii) = 1;
else
W(ii) = 2;
end
end
Wc = 1 + cumsum(W);
Wc(Wc<=160);
L = cumsum(Wc-1);
if find(L==0)
disp('1')
else
disp('0')
end
end

Best Answer

Change
if find(L==0)
disp('1')
else
disp('0')
end
to
if find(L==0)
result(c) = 1;
else
result(c) = 0;
end
Then after the end of the for loop,
sum(result)