Need help figuring out what I am doing wrong with my graph

my code::
function SumDice=RollDice(NumDice,NumRolls)
NumDice=1
NumRolls=500
distribution=zeros(NumDice*6,1);
for roll=1:NumRolls
diceValues = randi(6,[NumDice 1]);
totaldiceValue = sum(diceValues);
distribution(totaldiceValue) = distribution(totaldiceValue) +1;
end
valueMin = NumDice;
valueMax = 6 * NumDice;
bar(valueMin:valueMax, distribution(valueMin:valueMax), 'hist')
end
but i'm getting
The 1st graph has spaces and a difference x-axis scale which mine does not.
instead. any ideas? thanks!

 채택된 답변

Thomas
Thomas 2012년 11월 21일
use
bar(valueMin:valueMax, distribution(valueMin:valueMax))
with out the 'hist' option

추가 답변 (1개)

Matt Fig
Matt Fig 2012년 11월 21일

0 개 추천

What is the difference between the two graphs? The spaces between the bars? The title? The boldness of the lines? Be more specific.

댓글 수: 3

Matthew
Matthew 2012년 11월 21일
편집: Matthew 2012년 11월 21일
sorry, i edited it in my function. The 1st graph has spaces and a different y-axis scale which mine does not
They both have x-scale from 1 to 6. What is different about that?
You can set the width of the bars:
bar(valueMin:valueMax, distribution(valueMin:valueMax), .75,'hist')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2012년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by