how to fit gaussian model and plot it
78 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
michael scheinfeild
el 23 de Feb. de 2015
Editada: Liam Walsh
el 13 de Nov. de 2025 a las 15:20
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 comentarios
Respuesta aceptada
zepp
el 23 de Feb. de 2015
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 comentarios
Más respuestas (1)
Liam Walsh
el 11 de Nov. de 2025 a las 18:55
Editada: Liam Walsh
el 13 de Nov. de 2025 a las 15:20
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 comentarios
Ver también
Categorías
Más información sobre Probability Distributions and Hypothesis Tests en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

