tags:

views:

59

answers:

2

When trying to plot a normal PDF with mean=0 and standard deviation=20 using the MATLAB command normpdf() I get weird results, see picture.

alt text

The code used to plot the figure is as follows:

plot(normpdf((-100:0.1:100),0,20))

What is the correct way of using this function?

+1  A: 

I assume you expected the x-axis to be centered at 0? You need to specify an x-vector for plot. Try plot([-100:0.1:100], normpdf((-100:0.1:100),0,20));.

mtrw
+6  A: 

When you call plot with ONE argument, it plots those numbers on the y axis, using the index numbers of those values for the x axis. If you wanted the x axis scaled properly, you had to provide them in the first place. Thus...

x = -100:0.1:100;
plot(x,normpdf(x,0,20),'-')
woodchips
How stupid of me. Thanks a lot!
Ingo

related questions