This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/exercises/diehist.m

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