フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by