Reset initial value in for loop

2 views (last 30 days)
Emil Nilsson
Emil Nilsson on 29 Apr 2015
Answered: the cyclist on 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

Answers (1)

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

Categories

Find more on Loops and Conditional Statements 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!