Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Thomas Verhaegen
Thomas Verhaegen le 2 Déc 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
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.

Réponses (1)

KSSV
KSSV le 2 Déc 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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by