MATLAB: Storing fprintf as an array.

fprintf

The outcome of the code below gives H T H T T depending on random function. How do I store the outcome of the 20 iterations into a variable called 'product' ; for example: product =[ H T H T T......] so that whenever I need it, I can fetch the outcome by just typing 'product'
fprintf('The Outcomes are:\n')
for i = 1:20
A = rand(i,1);
if A(i) >= 0.5000
fprintf('%s\n', 'H');
else
fprintf('%s\n', 'T');
end
end

Best Answer

Why do a loop?
product=rand(1,20);
product(product>=.5)=72;
product(product<.5)=84;
product=char(product);
Related Question