Plot Normal/Gaussian distribution from set of data
32 views (last 30 days)
Show older comments
Hello All,
I want to plot a gaussian distribution of a set of data and see the mean and 3 sigma. I am using the below code but I am not getting the gaussian curve. Please help! Thanks!
x = [2.9954E-09,3.1314E-09,3.1155E-09,3.0940E-09,2.8861E-09,3.0875E-09,2.9685E-09,3.0532E-09,2.9003E-09,3.0931E-09];
[mu,s]=normfit(x,0,1);
%norm=normpdf(x,0,1);
figure; plot(x,norm);
figure; plot(x,norm);
Answers (1)
Image Analyst
on 7 Apr 2016
Try this:
x = [2.9954E-09 3.1314E-09 3.1155E-09 3.0940E-09 2.8861E-09 3.0875E-09 2.9685E-09 3.0532E-09 2.9003E-09 3.0931E-09];
norm=histfit(x,10,'normal')
[muHat, sigmaHat] = normfit(x);
% Plot bounds at +- 3 * sigma.
lowBound = muHat - 3 * sigmaHat;
highBound = muHat + 3 * sigmaHat;
yl = ylim;
line([lowBound, lowBound], yl, 'Color', [0, .6, 0], 'LineWidth', 3);
line([highBound, highBound], yl, 'Color', [0, .6, 0], 'LineWidth', 3);
line([muHat, muHat], yl, 'Color', [0, .6, 0], 'LineWidth', 3);
grid on;
% xFit = linspace(min(x), max(x), 100);
% yFit = max(x) * exp(-(xFit - muHat).^2/sigmaHat^2);
% figure;
% plot(xFit, yFit, 'r-', 'LineWidth', 2);
% grid on;
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Line segmentation', 'NumberTitle', 'Off')
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!