www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ReturnBarHeightsandBinCentersforaGivenNumberofBinsExample.m
%% Return Bar Heights and Bin Centers for a Given Number of Bins % Compute the bar heights for six bins using the empirical cumulative distribution % function and also return the bin centers. % Copyright 2015 The MathWorks, Inc. %% % 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. [n,c] = ecdfhist(f,x,6); [n' c']