Using if/else statement inside a for loop

5 Ansichten (letzte 30 Tage)
Rahul Sugatra
Rahul Sugatra am 30 Apr. 2019
Kommentiert: Rik am 1 Mai 2019
Greetings,
I'm running a "if" statement inside a for loop but the results doesn't consider the if statement conditions it just provides results with the last equation used in the loop. What I want is that for LocalTime between 9 to 16 if it is less than 12 then 1st equation should run upto 12'o clock then after 12 the 2nd equation values should be used and a final Results of 16(Hours)x31(days) should be generated.
*Solar Altitude Angle (SAA)*
for LocalTime=9:16
%U=(Time-((LST2-YY)+(S/2)))*15; %Hour Angle at LocalTime
U=(SNT-LocalTime)*15; %Hour Angle at LocalTime
HRADay(LocalTime,:)=U; %Hour Angle at LocalTime(Given Range)
SAA=asind((sind(d).*sind(Latitude))+(cosd(HRADay).*cosd(d).*cosd(Latitude)));
%%
% *Solar Azimuth Angle (SAZ)*
if LocalTime<=12
SAZ=abs(acosd((sind(d)-sind(SAA).*sind(Latitude))./(cosd(SAA).*cosd(Latitude))));
else
SAZ=360-abs(acosd((sind(d)-sind(SAA).*sind(Latitude))./(cosd(SAA).*cosd(Latitude))));
end
Results=SAZ;
end
  1 Kommentar
Rik
Rik am 1 Mai 2019
You are overwriting the result every loop iteration.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Data Type Conversion 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