for loop, conditional operator

2 Ansichten (letzte 30 Tage)
Kashfia Mahin
Kashfia Mahin am 16 Aug. 2019
Bearbeitet: Kashfia Mahin am 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.

Akzeptierte Antwort

James Tursa
James Tursa am 16 Aug. 2019
Bearbeitet: James Tursa am 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 Kommentar
Kashfia Mahin
Kashfia Mahin am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by