how to fit gaussian model and plot it
77 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
michael scheinfeild
le 23 Fév 2015
Modifié(e) : Liam Walsh
il y a environ 12 heures
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 commentaires
Réponse acceptée
zepp
le 23 Fév 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 commentaires
Plus de réponses (1)
Liam Walsh
le 11 Nov 2025 à 18:55
Modifié(e) : Liam Walsh
il y a environ 12 heures
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 commentaires
Voir également
Catégories
En savoir plus sur Probability Distributions and Hypothesis Tests dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

