필터 지우기
필터 지우기

Plot Normal/Gaussian distribution from set of data

조회 수: 20 (최근 30일)
Kash022
Kash022 2016년 4월 7일
댓글: Kash022 2016년 4월 7일
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);
  댓글 수: 1
Kash022
Kash022 2016년 4월 7일
I have managed to write this but can't calculate and plot mean and sigma.
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');
plot(x,norm);

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2016년 4월 7일
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')
  댓글 수: 1
Kash022
Kash022 2016년 4월 7일
Thanks! It works. Is there a way where I can show on the plot the mean and the 3 sigma?like an arrow showing the extent of the sigma?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by