0
votes

I have plotted a normal distribution from a set of data, x and y, using bar(x,y), and I know it's a normal distribution.

Now, I want to:

  1. Plot the normal distribution curve (or Gaussian), fitted to the bar-plot, in the figure.

  2. Get the equation, so that I can calculate the maximum point and the width at half maximum.

I have been looking at histfit but it doesn't really work for me (just like hist didn't work for plotting the data, as I already know both x and y, I think?). Can anyone help me?

1
Why histfit doesn't work for you? - Oleg
Probably because I don't know how to use it, even though I have read the description. My data is kinda like x=1, 1.2, 1.4, 1.6, 1.8, and y is the counts of each value of x, so e.g. y=0, 2, 6, 2, 0 - Niels Møller
histfit() works on raw data, but you already have it binned. Do you have original data? - Oleg
My data is from an experiment, which I know yields a normal distribution. I know both the x and y values. - Niels Møller

1 Answers

0
votes

A trick, which however does NOT recover the original raw data (therefore the fit suffers also from the approximations introduced by the binning), is to decode with the run-length algorithm your x, and run histfit() on that data:

% data from your previous question
x = [0 0.0278 0.0556 0.0833 0.1111 0.1389 0.1667 0.1945 0.2222];
y = [1 3 10 13 28 53 66 91 137];

% histfit 
histfit(rude(y,x),9,'normal')

where you can find the run-length encoding/decoding function on FEX: rude().

The result:

enter image description here