MATLAB: Histogram Normalization ‘pdf’ area under the curve less than 1

MATLAB

Why is the area under the curve (sum of bar areas) less than 1 for 'pdf' normalization in histograms?

Best Answer

When using the 'pdf' normalization in Histograms, note that the area of each bar is the relative number of observations. Therefore, the area under the curve could be less than or equal to 1.
An example of the area under the curve being less than 1 is having 'NaN' values in your data.
>> X = [1 1 2 nan];
>> h = histogram(X, 'Normalization', 'pdf')
>> sum(h.Values.*h.BinWidth)
Removing the NaN values from the data can be done like so -
>> X = X(~isnan(X))