If your input is specified as an irregular histogram, then simply using the built-in quantile() function, quantile() automatically calculates the data point for the specified quantile, which does the inverse CDF. If the histogram is normalized by the number of data points (which makes it a probability vector), then simply multiply it by the number of data points in the first place. See here for details of quantile() . Basically, you will assume that taking into account your histogram / data, the first parameter is fixed, which turns quantiles() into a function only from the given values โโof probability p . You can easily write a wrapper function to make it more convenient if necessary. This eliminates the need to explicitly compute CDF using cumsum() .
Added
If we assume that the histogram, bins, and the number of data points are h, b, and N respectively, then:
h1 = N*h; %// Only if histogram frequencies have been normalized. data = []; for kk = 1:length(h1) data = [data repmat(b(kk), 1, h1(kk))]; end %// Set p to the probability you want the inv-cdf for... p = 0.5; inv_cdf = quantiles(data,p)
Added
For solutions that must use an existing PDF vector, we can do the following. Suppose that x_old and pdf_old are histograms and histogram frequencies, respectively.
p = 0.5; %
Alternatively, we could first create cumsum() CDF and use interp1() if this is not desirable for interpolation first.
source share