25 lines
545 B
Matlab
25 lines
545 B
Matlab
% generate data:
|
|
x = randn( 1, 100000 );
|
|
|
|
% histogram:
|
|
[h,b] = hist( x, 100 );
|
|
% normalize:
|
|
bs = b(2)-b(1);
|
|
h = h/sum(h)/bs;
|
|
|
|
% plot:
|
|
bar( b, h );
|
|
xlabel( 'x' );
|
|
|
|
% median, quartile:
|
|
q = quartiles( x );
|
|
%q = quantile( x, [0.25, 0.5, 0.75 ] );
|
|
|
|
% plot:
|
|
hold on;
|
|
bar( b(b<q(1)), h(b<q(1)), 'FaceColor', [0.5 0 0.5] );
|
|
bar( b((b>=q(1)) & (b<q(2))), h((b>=q(1)) & (b<q(2))), 'FaceColor', [0.9 0 0] );
|
|
bar( b((b>=q(2)) & (b<q(3))), h((b>=q(2)) & (b<q(3))), 'FaceColor', [0 0 0.9] );
|
|
bar( b(b>=q(3)), h(b>=q(3)), 'FaceColor', [0.5 0 0.5] );
|
|
hold off;
|