problem with while condition

조회 수: 2 (최근 30일)
MC3105
MC3105 2014년 11월 18일
댓글: MC3105 2014년 11월 18일
Hey everyone,
I am using a while loop to calculate some radiation data for one year. I don't have much experience using matlab and have never used a while loop before so I think I included at least one mistake in my code. The loop s=0:23 is supposed to calculate the radiation data for one day. If the height of the sun is below 0 degrees (like at night times) the radiation data Clearness_syn is supposed to be zero. If the solar height is more than 0 degress I need my while-loop. If the calculated radiation data is too small (below 0) or to large (larger than Clearness_max), I want matlab to go back and recalculate. It shouldnt go forward in the code as long as these two conditions aren't fullfilled. So in the end I should not get values that are below zero for Clearness_syn. But I do... So I am guessing my while condition/loop is somehow wrong??
for t=1:8760
.......................% calculation of the different needed parameters, i left this out here
dif=1; % Initial value for dif
while dif==1
for s=0:23
if gamma(t+s)<=0 % Gamma is the height of the sun in degrees
ypsilon(t+s)=(Clearness_day(t)-Clearness_mean(t))/standarddev(t); % Initial value
Clearness_syn(t+s)=0;
elseif gamma(t+s)>0
rnum=standarddev(t+s)*sqrt(1-Autokorr(t+s)^2)*((rand^0.135-(1-rand)^0.135)/0.1975);
ypsilon(t+s)=Autokorr(t+s)*ypsilon(t+s-1)+rnum;
Clearness_syn(t+s)=Clearness_mean(t+s)+standarddev(t+s)*ypsilon(t+s);
Clearness_max=0.88*cosd(pi*(hour(datum(t))-12.5)/30); % maximal allowed value vor Clearness_syn
Clearness_min=0; % minimal allowed value for Clearness_syn
C=find(Clearness_syn(t:t+s));
C=Clearness_syn(C);
C=mean(C);
if Clearness_syn(t+s)<Clearness_min
dif=1;
elseif Clearness_syn(t+s)>Clearness_max
dif=1;
else
dif=0;
end
end
end
end
Thanks alot!!
  댓글 수: 5
Guillaume
Guillaume 2014년 11월 18일
Show your modified code with the while loop inside the for loop. You're probably not very far off what you need.
MC3105
MC3105 2014년 11월 18일
I cancelled the whole thing now... thanks anyways :D

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

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