ndies = 20; n = 100; P = zeros(ndies, 6); for i = 1:ndies % (a) roll a single die: x = rollthedie( n ); % (b) compute normalized histogram: [h,b] = hist( x, 1:6 ); h = h/sum(h); % normalization % (c) store the histograms: P(i,:) = h; end % (c) mean and standard deviation for each eye: m = mean(P, 1); s = std(P, 1); % (d) plot results: bar(m, 'facecolor', [0.8 0 0]); % darker red hold on; errorbar(m, s, '.k', 'linewidth', 2 ); % k is black set(gca, 'XTick', 1:6 ); xlim( [ 0, 7 ] ); ylim( [ 0, 0.25]) xlabel('Eyes'); ylabel('Probability'); hold off; savefigpdf(gcf, 'die2.pdf', 6, 5)