Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Thomas Verhaegen
Thomas Verhaegen 2016년 12월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
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.

답변 (1개)

KSSV
KSSV 2016년 12월 2일
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.

Community Treasure Hunt

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

Start Hunting!

Translated by