Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Storing output from a for loop into a matrix. When input value comes from .m script.

2 views (last 30 days)
I need to plot a histogram from my output data. I have written a script and know how to make this into a loop. However how can I get it into a matrix so i can make an Histogram.
kaart=5;
while kaart < 17
r = randi([1,10]);
if r==1
a= a+1;
r=11;
kaart=kaart+r;
else
kaart=kaart+r;
end
if kaart>21 && a > 0
kaart = kaart - 10;
a=a-1;
end
end
kaart
Above is the original script. I need to run this a 1000 times and make a histogram out of it. To run the for loop I have
for ii=1:1000;
Dealerscript;
end
However it does not allow me to make a histogram.

Answers (1)

KSSV
KSSV on 2 Dec 2016
kaart=5;
kaart1 = [] ;
while kaart < 17
r = randi([1,10]);
if r==1
a= a+1;
r=11;
kaart=kaart+r;
kaart1 = [kaart1 ; kaart] ;
else
kaart=kaart+r;
kaart1 = [kaart1 ; kaart] ;
end
if kaart>21 && a > 0
kaart = kaart - 10;
kaart1 = [kaart1 ; kaart] ;
a=a-1;
end
end
kaart1
May be you are looking for kaart values at the end. Check your a value, some times it goes to a condition where a is not defined.

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!