Asked by mutah
on 14 Sep 2013

this is my code to plot summation of 10 normpdf but when i plot figure the plot not like normpdf what the reason ??? plz answer me

w=[0.1139;0.0087;0.6147;0.0437 ; 0.1752;0.0115 ;0.0017;0.0198;0.0034;0.0074 ];

sigma=[0.0398;0.4716;0.4448;0.2984;0.1466;0.2828;1.3330;0.3010;0.0415;0.3592];

mu=[0.0074 ;4.9530;0.9306;2.8815;0.5280;4.0052;6.9460;2.4941;0.2566;3.4896];

x=0:20:80;

sum=0;

for i=1:10

y=w(i)*normpdf(x, mu(i), sigma(i));

sum=sum+y;

end

plot(x,sum);

grid on

Answer by Image Analyst
on 14 Sep 2013

First of all, DON'T use sum as the name of your variable because you'll no longer have access to the built-in function by that name. Call it "theSum" or something else.

Secondly, all you're doing is adding up a bunch of numbers to get a single number out, then you plot it (or try to). What do you expect to see? sum is not an array and does not have different values for different i - it's just a single number, not an array.

Azzi Abdelmalek
on 14 Sep 2013

sum has the same length then x

Image Analyst
on 14 Sep 2013

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Azzi Abdelmalek (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/87221-summation-in-matlab-help#comment_168994

## mutah (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/87221-summation-in-matlab-help#comment_169087

## Azzi Abdelmalek (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/87221-summation-in-matlab-help#comment_169127

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/87221-summation-in-matlab-help#comment_169128

Sign in to comment.