I have create function on Matlab like this:
function f = MMP2(x1,x2)
% returns PMF of a 2-dim MMPoi with specified discrete
% mixing distribution
lambdavalue=[1,1;2,2;3,3];
lambdaprob=[0.2;0.3;0.5];
f=0;
for i=1:length(lambdaprob)
f=f+exp(-lambdavalue(i,1))
*lambdavalue(i,1)^x1
/factorial(x1)
*exp(-lambdavalue(i,2))
*lambdavalue(i,2)^x2
/factorial(x2)
*lambdaprob(i);
end
Next, I want to call the function:
pmf=zeros(11,11);
for x1=0:10
for x2=0:10
pmf(x1+1,x2+1)=MMP2(x1,x2);
end
end
figure
bar3(pmf)
but it doesn't work! what is the mistake here? I tried several time but it doesn't work. Thanks advance.

 채택된 답변

Star Strider
Star Strider 2015년 9월 8일

1 개 추천

If you want to continue a statement across several lines, you have to use the ellipsis (...) operator.
This version of your loop works:
for i=1:length(lambdaprob)
f=f+exp(-lambdavalue(i,1))...
*lambdavalue(i,1)^x1...
/factorial(x1)...
*exp(-lambdavalue(i,2))...
*lambdavalue(i,2)^x2...
/factorial(x2)...
*lambdaprob(i);
end

댓글 수: 2

bader almulhim
bader almulhim 2015년 9월 8일
Thank you so much. It is working now.
Star Strider
Star Strider 2015년 9월 8일
My pleasure.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2015년 9월 8일

댓글:

2015년 9월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by