for loop, conditional operator

조회 수: 3 (최근 30일)
Kashfia Mahin
Kashfia Mahin 2019년 8월 16일
편집: Kashfia Mahin 2019년 8월 19일
for k=1:length(kinetic);
if (delta(j)<=kinetic(k)) && (j==k)
filling_degree_regionI(j,k)=1/(2*pi).*(pi*(abra)/180-((rh/R).*cosd(kappa-kinetic(k))./cosd(alpha).*sind(abra)./cosd(shai-kinetic(k))))
filling_degree_regionI_new(1,k)=filling_degree_regionI(j,k);
end
end
end
for i=1:length(filling_degree_regionI_new);
if filling_degree_regionI(i) > 0
new_filling_degree_regionI(i)=filling_degree_regionI(i);
end
end
Here, I have to calculate filling degree using delta and kinetics. Kinetics[1*13] are calculated using delta[1*13]=[0:10:180]. To calculate filling degree[1*13], delta should be less than equal to kinetics and length of delta and kinetics should be same. and also filling degree can't be zero. but there is some error showing there.
Undefined function or variable 'filling_degree_regionI_new'.
i can't figure it out how to solve it.

채택된 답변

James Tursa
James Tursa 2019년 8월 16일
편집: James Tursa 2019년 8월 16일
You are creating the variable filling_degree_regionI_new inside a condition if statement. If the condition is never met, the variable filling_degree_regionI_new will not be created.
Maybe you could describe in words what variables you are starting with, what they contain, and what calculation you hope to do with them. We might be able to suggest a better way than what you are currently doing. E.g., what is the point of your double for-loops at the beginning if you don't take any action unless j==k? A single for-loop would suffice.
  댓글 수: 1
Kashfia Mahin
Kashfia Mahin 2019년 8월 17일
Thanks for your reply.
I have [1*13] values of delta which are arranged [-90:30:270]. I use delta arrays to calculate kinetic[1*13]. Now I have to calculate filling degree using delta and kinetics. different filling depends on the values of delta and kinetic. it would be like that- filling_degree_regionI(1) will be calculated using delta(1) and kinetic(1). for filling_degree_regionI(2), delta(2) and kinetic(2) are needed.
but there are two condition-
1) delta has to be less than equal to kinetics.
I wrote j==k because I used two loops. I am confused how to make algorithms.

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

추가 답변 (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