Reset initial value in for loop

3 visualizaciones (últimos 30 días)
Emil Nilsson
Emil Nilsson el 29 de Abr. de 2015
Respondida: the cyclist el 29 de Abr. de 2015
The code describes how the room temperature, T_inside changes due to heat transfer from the outside temperature and from incoming solar radiation. Here is the loop used to update T_inside:
for n=1:1:nt
T_outside=16+8*sin(time*pi/(12*3600));
Heat_transfer=U*A*(T_inside-T_outside);
Collected_power=(Transmission-Heat_transfer);
T_inside=T_inside+(Collected_power*dt)/(Cpair*Dair*V);
time=time+dt;
end
I want to reset T_inside to 20 degrees as soon as T_inside reaches 22 degrees, and then continue the loop with T_inside=20 as the initial value. How can I do this?
Thanks in advance, Emil

Respuestas (1)

the cyclist
the cyclist el 29 de Abr. de 2015
Put these lines inside your loop.
if T_inside>=22
T_inside = 20;
end

Categorías

Más información sobre Loops and Conditional Statements 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