how to fit gaussian model and plot it
72 次查看(过去 30 天)
显示 更早的评论
hi i have vector of 1000 numbers i want to fit Gaussian model i use
[n,cent]=hist(x,50)
then
bs = glmfit(cent,n,'normal');
then i want to plot the fit yfit = glmval(bs,cent_s); failed Error using glmval (line 64) At least three arguments are required. i want to plot
plot(cent_s,yfit)
0 个评论
采纳的回答
zepp
2015-2-23
You can do the following:
1) Estimate the mean and standard deviation using normfit
2) Calculate the probability estimates using normpdf
3) Plot the data and the estimates using plot
Example:
[m,s] = normfit(x);
y = normpdf(x,m,s);
plot(x,y,'.');
0 个评论
更多回答(1 个)
Liam Walsh
31 minutes 前
glmfit and glmval fit and evaluate generalized linear models, respectively. These can be used to model Gaussian data, but you need a set of predictors and responses (which are Gaussian).
If you have a single vector of Gaussian data that you want to fit to a Gaussian distribution, then there are two ways you can go about this. First, you can use normfit, normpdf, etc, as zepp shows in their answer.
Alternatively, you can make use of the fitdist function to create a NormalDistribution object, which has many convenience functions for visualizing the fit. To see all the options for working with the normal/Gaussian distribution that Statistics and Machine Learning Toolbox provides, please consult the following documentation page:
% Create some sample data
rng(0, 'twister') % For reproducibility
x = normrnd(10, 2, 100, 1);
% Example 1: normfit, normpdf
[mu, sig] = normfit(x)
grid = 3:.1:17;
pdfvals = normpdf(grid, mu, sig);
plot(grid, pdfvals)
% Example 2: fitdist
normdist = fitdist(x, "normal") % Same mu, sigma values as the first example
plot(normdist)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

