Using if/else statement inside a for loop
6 views (last 30 days)
Show older comments
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 Comment
Answers (0)
See Also
Categories
Find more on Data Type Conversion 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!