Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

KSSV
KSSV il 2 Dic 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.

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by