Aly
Aly

Reputation: 16255

Matlab: How to plot normal curve from mean and standard deviation

I have a mean and standard deviation, I want to plot a normal curve with no labels on the axis and no grid lines. I have searched and found this:

r = mean + std.*randn(100,1);
histfit(r)

But this has the histogram bars, and grid lines and axis tickers.

Thanks

Upvotes: 2

Views: 22129

Answers (4)

sukkub
sukkub

Reputation: 11

You can use Normal probability density function. This, combined with Eitan T's answer, would give

mu = 4;                                %// Mean
sigma = 0.2                            %// Standard deviation

%// Plot curve
x = (-5 * sigma:0.01:5 * sigma) + mu;  %// Plotting range
plot(x, normpdf(x,mu,sigma));

%// Hide ticks
set(gca, 'XTick', [], 'XTickLabel', [], 'YTick', [], 'YTickLabel', [])

and would result in the same figure. Only that you would use a MATLAB in-built function instead of coding it on your own.

Upvotes: 0

Eitan T
Eitan T

Reputation: 32930

Just compute the corresponding Gaussian curve and plot it.

Example

Let's plot a Gaussian curve with 4 mean and 0.2 standard deviation:

mu = 4;                                %// Mean
sigma = 0.2                            %// Standard deviation

%// Plot curve
x = (-5 * sigma:0.01:5 * sigma) + mu;  %// Plotting range
y = exp(- 0.5 * ((x - mu) / sigma) .^ 2) / (sigma * sqrt(2 * pi));
plot(x, y)

%// Hide ticks
set(gca, 'XTick', [], 'XTickLabel', [], 'YTick', [], 'YTickLabel', [])

The result is:

result

Upvotes: 4

0x90
0x90

Reputation: 40982

Why don't you use:

R = normrnd(mu,sigma)
normplot(R)

Upvotes: 2

duffymo
duffymo

Reputation: 308763

Since you have mean and standard deviation, why can't you just plot this?

https://en.wikipedia.org/wiki/Normal_distribution

That's the function you're interested in. Just loop over values in the range of

(mean - 3*stddev) <= x <= (mean + 3*stddev)

Upvotes: 0

Related Questions