16 lines
353 B
Matlab
16 lines
353 B
Matlab
function diehist(x)
|
|
% plots a normalized histogram of integer random numbers x
|
|
% drawn from rolling a die.
|
|
maxx = max(x);
|
|
[h,b] = hist(x, 1:maxx);
|
|
h = h/sum(h); % normalization
|
|
plot([0 maxx+1], [1/maxx 1/maxx], 'r', 'linewidth', 3)
|
|
hold on
|
|
bar(b, h);
|
|
hold off
|
|
set(gca, 'XTick', 1:maxx);
|
|
xlim([ 0, maxx+1]);
|
|
xlabel('Eyes');
|
|
ylabel('Probability');
|
|
end
|