필터 지우기
필터 지우기

How to write if else program on matlab?

조회 수: 1 (최근 30일)
Drishya Dinesh
Drishya Dinesh 2020년 3월 19일
편집: Drishya Dinesh 2020년 3월 21일
This is the program, but it is not working. My output is always 5. But why? How to correct it? It is written as a matlab function in simulink.
PROGRAM:
function betaref = fcn(w)
if (w<5)
betaref=45;
elseif (5<w<15)
betaref=5;
elseif (15<w<25)
betaref=0;
else
betaref=90;
end
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2020년 3월 19일
Run
value = fcn(0);
It returns 45 on my system,
Drishya Dinesh
Drishya Dinesh 2020년 3월 19일
편집: Drishya Dinesh 2020년 3월 19일
Thankyou for your reply!
This is my simulink diagram. My output should track betaref. My input is 25 which implies betaref should be zero. But i have 5 instead.

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

답변 (1개)

Steven Lord
Steven Lord 2020년 3월 19일
elseif (0<power<=1000)
This doesn't do what you think it does. If you're writing this code in the MATLAB Editor and you're using a relatively recent release you should have received a Code Analyzer warning alerting you to that fact (an orange line in the right scroll bar for the Editor window and orange underlines of part of this construct.)
Instead:
elseif (0<power & power<=1000)
  댓글 수: 1
Drishya Dinesh
Drishya Dinesh 2020년 3월 19일
Thankyou for your reply!
What if my program is like,
function betaref = fcn(w)
if (w<5)
betaref=45;
elseif (5<w<15)
betaref=5;
elseif (15<w<25)
betaref=0;
else
betaref=90;
end

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

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by