Creating a script with multiple conditions and equations

Hi! I'm a beginner to matlab and I have to create a side script to my headscript where I have conditions for the value of the temperature.
For example:
The temperature inside = 36,44-0,64Toutside if T outside is less than -4 but if it's greater I'll have to use a different equation.
I assume that I have to create some sort of if coding. But how do I direct to condition to an equation?
Sorry if it's hard to understand the question and super thanks in advance for the help.
William

답변 (2개)

William Ewerblad
William Ewerblad 2022년 12월 5일
Would something like this work? or how do I link it to the main page
if T_ute < -4
'eqn = 36.44-(0.64*T_ute)';
elseif T_ute <= 4.0
'eqn = 39.0';
elseif T_ute <= 21.0
'eqn = 43.26 - (1.06*T_ute)';
elseif T_ute > 21
'eqn = T_ute' ;
end
Torsten
Torsten 2022년 12월 5일
편집: Torsten 2022년 12월 5일
T = @(T_ute) (36.44 - 0.64*T_ute).*(T_ute<-4) + 39*(T_ute>=-4 & T_ute<=4) + (43.26 - 1.06*T_ute).*(T_ute > 4 & T_ute <=21) + T_ute.*(T_ute>21);
T_ute = -10:1:30;
plot(T_ute,T(T_ute))

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2022년 12월 5일

편집:

2022년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by