% L3B demo % Roll a fair die 12 times. % Show two plots: % Left, GENERATING distribution (of the probabilities) % Right, EMPIRICAL distribution (from the observed counts) % % Optionally, use a particular nonuniform generating distribution. % function L3Bdicedemo(unfair) if nargin<1, unfair=false; end if unfair % A slightly unfair die that favors 1 and 6 p = [.20 .15 .15 .15 .15 .20]; else p = ones(1,6) / 6; end x = randsample(1:6, 12, true, p); nk = hist(x, 1:6); emp_p = nk/sum(nk); % Find largest probability in either plot % so we can ensure same scaling maxp = max(max(p),max(emp_p)); subplot(1,2,1) bar(1:6, p) title('Generoiva jakauma') set(gca, 'ylim', [0 maxp+0.05]); subplot(1,2,2) bar(1:6, emp_p) title('Empiirinen jakauma') set(gca, 'ylim', [0 maxp+0.05]); end