How to commit statement only under certain conditions?

1 次查看(过去 30 天)
Hello, I'm simulating water heating and I need to create certain condition and I dont know how to create it properly.
Required temperature of water is 55 °C. Minimal temperature is 50 °C. Maximum temperature is 70 °C.
I have 2 types of heating - electrical heating which heats water to required temperature 55 °C and photovoltaic heating which can heat water to maximum temperature.
I need to create condition which turn on electrical heating only if temperature drops below 50 °C and stops after reaching 55 °C. If the temperature is between 50 and 55 without dropping under 50 °C only photovoltaic heating is possible and electrical heating is off.
Temperature is checked every minute for whole year. Conditions will be placed in for cycle. I dont know how to create condition for starting electrical heating under 50 and stopping at 55.
Something like that:
if temperature < 70
photovoltaic on
else
everything off
if temperature < 50
electrical heating on and stops at 55°C
Thanks for advice.

采纳的回答

Jan
Jan 2017-2-26
编辑:Jan 2017-2-26
electric = true;
photovoltaic = false;
for iMinute = 1:365*24*60
if temperature(iMinute) < 50
electric = true;
elseif temperature(iMinute) > 55
electric = false;
end
photovoltaic = (temperature(iMinute) < 70);
...
end
  7 个评论
Jan
Jan 2017-2-27
编辑:Jan 2017-2-27
@LamaObencna: The code you have shown here, does not contain the code for changing the temperature. The part of detecting, which heating is enabled, was discussed exhaustively already, and it cannot cause the observed behavior alone. You can replace it for testing: Keep the photovoltaic and/or electric heating enabled manually and examine, what happens.
Something like "it ignores 55 °C condition" cannot happen. Matlab is not in a bad mood and ignores any line. I really want to help you and I'm convinced the problem is not included in the part of the code, which has been posted here. So please start testing the code I've suggested if it enables the heat sources exactly as you want it. Then we can proceed and find out, why the correct values do not yield the expected result in the change of the temperature.
LamaObecna
LamaObecna 2017-2-27
编辑:LamaObecna 2017-2-27
Done. I figured it out with help of community of stackoverflow, basicly very similar to your idea. I should show whole code, it would be easier to get it work, my mistake. Anyway, thank you for your time and advice. I have marked your answer as accepted becouse it was right direction.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Energy Production 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by