필터 지우기
필터 지우기

Calling Functions and using a loop

조회 수: 1 (최근 30일)
Amine Ben Ayara
Amine Ben Ayara 2015년 9월 1일
편집: Stephen23 2015년 9월 1일
I am having trouble calling a function that I have created already and saved in an m.file. The objective is to write a for--loop where the function is called and one of its input variables (Matrices) will change three times. This is the code:
function [M1] = ProbabiltyCounty1(X, Lam ,YC1)
x=X;
for MySimul=0:10
X(:,4)= X(:,4)+MySimul;
for Periods=1:9
for LandYs=1:3
for Coefs=1:3
Den(Periods,LandYs)=exp (YC1(Periods+1,LandYs)* dot(X(Periods,:),Lam(1,:))) + exp(YC1(Periods+1,LandYs)* dot(X(Periods,:),Lam(2,:))) +exp(YC1(Periods+1,LandYs)* dot(X(Periods,:),Lam(3,:)));
MN(LandYs,Coefs,Periods) = exp(YC1(Periods+1,LandYs)* dot(X(Periods,:),Lam(Coefs,:)))/Den(Periods,LandYs);
end
end
end
Ml =transpose(transpose(MN(:,:,1))* transpose(YC1(2,:)));
for Periods=2:9
Ml(Periods,:)=transpose(transpose(MN(:,:,Periods))* transpose(Ml(Periods-1,:)));
end
M1(:,:,MySimul+1)=Ml;
X=x;
end;
When I created a new script and wrote a loop: For i=1:3 and called the function, matlab didn't read it or even locate my m.file. I need the output of the original function to change everytime the values of YC1 variable (matrix) changes. Please help.
  댓글 수: 1
Stephen23
Stephen23 2015년 9월 1일
편집: Stephen23 2015년 9월 1일
This time I formatted your code for you , but in future please do it yourself by selecting the code text and clicking the {} Code button that you will find above the textbox.
It would help us if you use consistent leading whitespace (four spaces per tab) and please do not include blank lines in your code.
Now to your problem: yre you getting and error message? If so, what exactly? How are you calling the function? Is the folder where the function is saved on your MATLAB path?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by