开发者

How does MATLAB's normpdf function work?

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.

How does MATLAB's normpdf function work?

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?


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),'-')


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));.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜