My loop doesn't continue after first iteration. The two vectors Q and T do not have values when m=2. The file where I get my values is a table. H is the lenght of an excel file (table as well) with a number of different hydrometric stations from which I want the info
for m=1:H
Station=Sta{m,1};
Donnees=Donnees(strcmp(Donnees.NoStation, Station),:);
Q=Donnees{:,5};
T=Donnees{:,7};
[beta_qt,R_qt,J_qt,CovB_qt,MSE_qt]=nlinfit(Q,T,@(b,Q)(b(1)*Q.^(b(2))),[1 1]);
Tm=beta_qt(1)*Q.^beta_qt(2);
RMSE_qt=sqrt(MSE_qt);
A(m,1:3)=[Station beta_qt(1) beta_qt(2)];
end
I tried a while loop and it didn't help.

답변 (1개)

John D'Errico
John D'Errico 2018년 5월 30일
편집: John D'Errico 2018년 5월 30일

1 개 추천

What if loop? An if is not a loop. And you have no ifs in this code anyway. I'll assume you meant to say a for loop. A while loop would make no difference, and I have a funny feeling you don't understand why you might use a while loop anyway. A for loop is appropriate when you have a fixed set to iterate over, here that is 1:H. You would use a while loop if you don't know how long the loop will continue, but you know when it is done. (So a while loop is something SOME Supreme court justices would comprehend.) Regardless ...
What is Donnees? You use it almost like a function, here:
Donnees=Donnees(strcmp(Donnees.NoStation, Station),:);
at least on the left hand side. But then you overwrite it as a variable named Donnees. That is REALLY bad programming style.
Worse, then you seem to be accessing it as a cell array. Sheesh. Make up your mind. You are asking for bugs galore if you continue to write code like this.
Anyway, the second time through the loop, this will fail, because you just overwrote Donnees, whatever it is, on the first pass through the loop.

댓글 수: 1

Justin Moreault
Justin Moreault 2018년 5월 31일
Yeah, I found out that what I was doing with Donnees wasn't good. Thanks for the critism, I'm just beginning to work with Matlab and programming in general!

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

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 5월 30일

댓글:

2018년 5월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by