Reset initial value in for loop

3 Ansichten (letzte 30 Tage)
Emil Nilsson
Emil Nilsson am 29 Apr. 2015
Beantwortet: the cyclist am 29 Apr. 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

Antworten (1)

the cyclist
the cyclist am 29 Apr. 2015
Put these lines inside your loop.
if T_inside>=22
T_inside = 20;
end

Kategorien

Mehr zu Loops and Conditional Statements 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