Using if/else statement inside a for loop

5 visualizaciones (últimos 30 días)
Rahul Sugatra
Rahul Sugatra el 30 de Abr. de 2019
Comentada: Rik el 1 de Mayo de 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 comentario
Rik
Rik el 1 de Mayo de 2019
You are overwriting the result every loop iteration.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by