필터 지우기
필터 지우기

summation in matlab help

조회 수: 1 (최근 30일)
mutah
mutah 2013년 9월 14일
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
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 15일
Ok, but that's what your code is doing. If the result is not what you are expecting, then tell us what is the wanted result
Walter Roberson
Walter Roberson 2013년 9월 15일
If I understand correctly, you are expecting that normpdf() will return a vector, since you pass in a vector for x.
I do not have that toolbox, so I cannot experiment to be sure, but it does look to me as if it should be returning a vector.
You should put a breakpoint in on the line after you calculate y, run the program, and examine y to see what result you get.

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2013년 9월 14일
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.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 14일
sum has the same length then x
Image Analyst
Image Analyst 2013년 9월 14일
I think that either y or theSum might want to take an index: y(i) or theSum(i). Or he could just calculate theSum after the loop if he indexes y: theSum = sum(y). Unfortunately I don't have the normpdf() function so I can't really fix the code, plus lack of comments make it unclear what he wants to do.

댓글을 달려면 로그인하십시오.


mutah
mutah 2013년 9월 15일
any body can correct my code or try to plot

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by