MATLAB: How to commit statement only under certain conditions

conditionsif statement

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.

Best Answer

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
Related Question