필터 지우기
필터 지우기

For loop or if condition?

조회 수: 2 (최근 30일)
Nikola
Nikola 2013년 8월 23일
Hi,
I solved system of differential equations that present temperature values in two rooms. Now, I want to apply thermostat control which is active if temperature drops below 18 or go above 20 degrees. Is this loop correct?
for i=1:t t(i)=84600; if(T(i)>=18 && T(i)<=20) go else stop end end
Or is better to use if statement?
Thanks in advance!
  댓글 수: 1
Nikola
Nikola 2013년 9월 5일
Hi,
I defined heater function apart from function which solves system of equations. Now, I embed heater function into function with equations since I want to make responses of the heater when temperature is out of given bounds.
Can I send you code to see is it correct or suggest me what can I do to fix that?
Thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

UJJWAL
UJJWAL 2013년 8월 23일
First of all, this is not a correctly asked question.
Put your code in a correct format and be of a more explanatory nature.
While you mention 'OR' in your question , the code contains '&&' which stands for "AND".

추가 답변 (1개)

Nikola
Nikola 2013년 8월 23일
Hi,
Thanks for quick answer. I used this procedure bu program reports some error. Yes, I know meaning of this logical operators but I didn't set question well.
So, if for loop reports error, should I use if statement instead?
  댓글 수: 6
Nikola
Nikola 2013년 8월 27일
Hi, I solved system and now I have to define another function called heater. Heater should be function [on,off] = heater(T1,T2) on = true; off = else; if(T1<18 (T1>= 18 && T1<=20)) heater on = 1; else if (T2<18 (T2>=18 && T2<= 20)) heater on = 1; else heater off = 1; end;
Could you check is it correct and should I make some corrections? Thanks a lot in advance!
Nikola
Nikola 2013년 8월 28일
@UJJWAL Hi, I solved system and now I have to define another function called heater. Heater should be function [on,off] = heater(T1,T2) on = true; off = else; if(T1<18 (T1>= 18 && T1<=20)) heater on = 1; else if (T2<18 (T2>=18 && T2<= 20)) heater on = 1; else heater off = 1; end;
Could you check is it correct and should I make some corrections? Thanks a lot in advance!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by