Debian Codegraph @

texmf-dist/doc/latex/thucoursework/matlabscript.m

raw
1 n = 1e6; % n samples
2 data = randn(1e6, 1); % Generate n Random Gaussian samples.
3 nbins = 50; % bins in your histogram
4 [cnt, x_hist] = hist(data, nbins); % not to plot, only to get emperical distribution.
5 figure;
6 cnt = cnt / n / (x_hist(2) - x_hist(1)); % normalization, be careful :)
7 bar(x_hist, cnt); % plot the hist using bar()
8 hold on;
9 x = -5 : 0.1 : 5;
10 plot(x, normpdf(x), 'r', 'linewidth', 2);
11 legend({'$\hat{p}_{\sf{x}}(x)$', '$p_{\sf{x}}(x)$'}, 'Interpreter', 'LaTeX', 'fontsize', 15);
12 xlabel('$x$', 'Interpreter', 'LaTeX', 'fontsize', 15); % You may change the size accordingly
13 ylabel('$p_{\sf{x}}(x)$', 'Interpreter', 'LaTeX', 'fontsize', 15);
14 title("\mlplaceholder{your-title-here}")