[n,c] =
ecdfhist(f,x) returns
the heights, n, of histogram bars for 10 equally
spaced bins and the position of the bin centers, c.

ecdfhist computes the bar heights from the
increases in the empirical cumulative distribution function, f,
at evaluation points, x. It normalizes the bar
heights so that the area of the histogram is equal to 1. In contrast, hist produces bars with heights representing
bin counts.

Compute the histogram bar heights based on the empirical cumulative distribution function.

Generate failure times from a Birnbaum-Saunders distribution.

rng('default') % for reproducibility
failuretime = random('birnbaumsaunders',0.3,1,100,1);

Assuming that the end of the study is at time 0.9, mark the generated failure times that are larger than 0.9 as censored data and store that information in a vector.

T = 0.9;
cens = (failuretime>T);

Compute the empirical cumulative distribution function for the data.

[f,x] = ecdf(failuretime,'censoring',cens);

Now, find the bar heights of the histogram using the cumulative distribution function estimate.

Compute the bar heights for six bins using the empirical cumulative distribution function and also return the bin centers.

Generate failure times from a Birnbaum-Saunders distribution.

rng('default') % for reproducibility
failuretime = random('birnbaumsaunders',0.3,1,100,1);

Assuming that the end of the study is at time 0.9, mark the generated failure times that are larger than 0.9 as censored data and store that information in a vector.

T = 0.9;
cens = (failuretime>T);

First, compute the empirical cumulative distribution function for the data.

[f,x] = ecdf(failuretime,'censoring',cens);

Now, estimate the histogram with six bins using the cumulative distribution function estimate.

Draw the histogram of the empirical cumulative distribution histogram for specified bin centers.

Generate failure times from a Birnbaum-Saunders distribution.

rng('default') % for reproducibility
failuretime = random('birnbaumsaunders',0.3,1,100,1);

Assuming that the end of the study is at time 0.9, mark the generated failure times that are larger than 0.9 as censored data and store that information in a vector.

T = 0.9;
cens = (failuretime>T);

Define bin centers.

centers = 0.1:0.1:1;

Compute the empirical cumulative distribution function for the data and draw the histogram for specified bin centers.

Generate right-censored survival data and compare the histogram from cumulative distribution function with the known probability distribution function.

Generate failure times from an exponential distribution with mean failure time of 15.

rng('default') % For reproducibility
y = exprnd(15,75,1);

Generate drop-out times from an exponential distribution with mean failure time of 30.

d = exprnd(30,75,1);

Record the minimum of these times as the observed failure times.

t = min(y,d);

Generate censoring by finding the generated failure times that are greater than the drop-out times.

censored = (y>d);

Calculate the empirical cdf and plot a histogram using the empirical cumulative distribution function.

[f,x] = ecdf(t,'censoring',censored);
ecdfhist(f,x)
set(get(gca,'Children'),'FaceColor',[.8 .8 1])
hold on

Superimpose a plot of the known population pdf.

xx = 0:.1:max(t);
yy = exp(-xx/15)/15;
plot(xx,yy,'r-','LineWidth',2)
hold off