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/code/gaussianbins.m
2015-10-31 20:45:32 +01:00

27 lines
481 B
Matlab

x = randn( 100, 1 ); % generate some data
db1=2;
db2 = 0.5;
bins1 = -4:db1:4; % large bins
bins2 = -4:db2:4; % small bins
[h1,b1] = hist(x,bins1);
[h2,b2] = hist(x,bins2);
subplot( 1, 2, 1 );
bar(b1,h1)
hold on
bar(b2,h2, 'facecolor', 'r' )
xlabel('x')
ylabel('Frequency')
hold off
% normalize:
hn1 = h1/sum(h1)/db1;
hn2 = h2/sum(h2)/db2;
subplot( 1, 2, 2 )
bar(b1,hn1)
hold on
bar(b2,hn2, 'facecolor', 'r' )
xlabel('x')
ylabel('Probability density')
hold off