Calling Functions and using a loop

1 visualizzazione (ultimi 30 giorni)
Amine Ben Ayara
Amine Ben Ayara il 1 Set 2015
Modificato: Stephen23 il 1 Set 2015
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 Commento
Stephen23
Stephen23 il 1 Set 2015
Modificato: Stephen23 il 1 Set 2015
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?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by