Question

I have some data in the form of a histogram that I want to fit a Gaussian to, so I just need to find the variance and mean of the data for the best approximation. I was just testing out what I was going to do with something like

average = 50;
variance = 10;
gauss = normpdf( (1:100), average, variance); %generate gaussian

I should be able to retrieve the mean and variance exactly right? I seem to be getting close to the mean somewhere around 49, but no matter what I try I can't seem to get the variance. This seems relatively simple. Maybe I'm just tired but I'm getting nowhere. How would one go about retrieving the mean and variance from this sample data?

edit: I cant get the mean now, I was just off by 1 before (stupid mistake). Still clueless on the variance at the moment

Was it helpful?

Solution

The third input to normpdf is standard deviation, not variance. So, use

gauss = normpdf( (1:100), average, sqrt(variance)); %// generate Gaussian
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top