0

I have x data and I did binning and created histogram of each bin.Now I want to fit the probability distribution function in each bin so I can see histogram and probability distribution function at the same graph. Here 'X' is in horizontal axis data and 'Y' represent vertical axis data of the same datasets. I have written the code below

 X = load data1 ; Y = load data2   
topEdge = 10; % upper limit
botEdge = 0;
numBins = 20;  


binEdges = linspace(botEdge, topEdge, numBins+1); 
[h,whichBin] = histc(X, binEdges)

% Histrogram plot of each bin

for i = 1:numBins


flagBinMembers = (whichBin == i); %Creates vector of the indices of the data entries that are in bin i
BinMean(i) = mean(power_ref(flagBinMembers)); %Calculate mean value in this bin
BinStd(i) = std(power_ref(flagBinMembers)); 
x = power_ref(flagBinMembers) - BinMean(i);
mu = power_ref(flagBinMembers)- BinMean(i); sigma =power_ref(flagBinMembers)- BinStd(i);

  figure();
 histogram(x, 'Normalization', 'pdf')
 hold on;
 Y = normpdf(x,mu,sigma);
  plot(x,Y); 
  hold off
end

After running this code I am not getting the fitted 'pdf' and histogram on same curve. I correctly got histogram but not 'pdf'. Can any one suggest me or help me ....?? Thank you for your such patient for reading this !

I am getting such curve output : output of first bin Output of 2nd bin

As you can see histogram and pdf not fitting. Where I am making mistake...??

ravi pandit
  • 117
  • 12
  • you want the probabilty distribution in each bin? inside the bin they won't for sure not be normal distributed. Do you want to draw the bins and a norml distribution over all bins? – Finn Aug 03 '16 at 08:19
  • @Finn yes I want Probability distribution in each bin. Inside the bin I want to use probability distribution function because my distribution is look like Gaussian. – ravi pandit Aug 03 '16 at 09:49

0 Answers0