for loop, conditional operator

4 views (last 30 days)
Kashfia Mahin
Kashfia Mahin on 16 Aug 2019
Edited: Kashfia Mahin on 19 Aug 2019
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.

Accepted Answer

James Tursa
James Tursa on 16 Aug 2019
Edited: James Tursa on 16 Aug 2019
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 Comment
Kashfia Mahin
Kashfia Mahin on 17 Aug 2019
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!