19 lines
654 B
Matlab
19 lines
654 B
Matlab
x = randn(200, 1); % generate some data
|
|
xs = sort(x); % sort the data
|
|
cdf = [1:length(x)]/length(x); % cumulative
|
|
plot(xs, cdf);
|
|
hold on;
|
|
|
|
dx = 0.01;
|
|
xx = [-4:dx:4]; % x-values for Gaussian pdf
|
|
gauss = exp(-0.5*xx.^2)/sqrt(2.0*pi); % Gaussian pdf
|
|
gausscdf = cumsum(gauss)*dx;
|
|
plot(xx, gausscdf);
|
|
hold off;
|
|
|
|
printf('data : probability of x<-1: %.2f\n', cdf(xs<-1.0)(end))
|
|
printf('gauss: probability of x<-1: %.2f\n', gausscdf(xx<-1.0)(end))
|
|
printf('\n')
|
|
printf('data : 5%% percentile at %.2f\n', xs(cdf<0.05)(end))
|
|
printf('gauss: 5%% percentile at %.2f\n', xx(gausscdf<0.05)(end))
|