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)

采纳的回答

zepp
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,'.');

更多回答(1 个)

Liam Walsh
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)
mu = 10.2462
sig = 2.3248
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
normdist =
NormalDistribution Normal distribution mu = 10.2462 [9.78488, 10.7075] sigma = 2.3248 [2.04119, 2.70066]
plot(normdist)

类别

Help CenterFile Exchange 中查找有关 Probability Distributions and Hypothesis Tests 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by