Draw a graph of the normal distribution of the sample in Matlab

I have 100 sample numbers, and I need to draw their normal curve in the matrix.

The mean and standard deviation of these sample data can be easily calculated, but is there any function that displays the normal distribution?

+5
source share
3 answers

If you have access to the Statistics Toolbox, the function histfitdoes what it seems to you:

>> x = randn(10000,1);
>> histfit(x)

Normal distribution plot

As with the command hist, you can also specify the number of mailboxes, and you can also specify which distribution is used (by default it is a regular distribution).

, , @Gunther @learnvst.

+7

hist:

hist(data)

:

enter image description here

, :

hist(data,5)

pdf, , :

mu=mean(data);
sg=std(data);
x=linspace(mu-4*sg,mu+4*sg,200);
pdfx=1/sqrt(2*pi)/sg*exp(-(x-mu).^2/(2*sg^2));
plot(x,pdfx);

, hist ( , , pdf 0-1, : ).

+5

, , , .

STD = 1;
MEAN = 2;
x = -4:0.1:4;
f = (   1/(STD*sqrt(2*pi))   )  *  exp(-0.5*((x-MEAN)/STD).^2  );

hold on; plot (x,f);

The array xin this example is the xaxis of your distribution, so change it to any range and sample density.

If you want to draw a Gaussian fit to your data without the help of signal processing tools, the following code will draw such a graph with the correct scaling. Just replace ywith your own data.

y = randn(1000,1) + 2;
x = -4:0.1:6;

n = hist(y,x);

bar (x,n);

MEAN = mean(y);
STD = sqrt(mean((y - MEAN).^2));


f = (   1/(STD*sqrt(2*pi))   )  *  exp(-0.5*((x-MEAN)/STD).^2  );
f = f*sum(n)/sum(f);

hold on; plot (x,f, 'r', 'LineWidth', 2);

enter image description here

+4
source

All Articles