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:100n = 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; endendWc = 1 + cumsum(W); Wc(Wc<=160);L = cumsum(Wc-1);if find(L==0) disp('1')else disp('0')endend
Best Answer