필터 지우기
필터 지우기

Reset initial value in for loop

조회 수: 3 (최근 30일)
Emil Nilsson
Emil Nilsson 2015년 4월 29일
답변: the cyclist 2015년 4월 29일
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

답변 (1개)

the cyclist
the cyclist 2015년 4월 29일
Put these lines inside your loop.
if T_inside>=22
T_inside = 20;
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by