Calling Functions and using a loop

1 次查看(过去 30 天)
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