function cointosses2(n,p) % Simulate tossing a coin n times, with probability p of % heads, but suppress the result and print only the proportion of heads A = 0; heads = 0; for i=1:n if rand<=p A = [A,'H']; heads = heads+1; else A = [A,'T']; end end % disp(['The result of tossing a coin ', num2str(n) ' times is ', num2str(A(1,2:n+1))]) disp(['The proportion of heads is ', num2str(heads/n)])