How to us variable as an if statement condition?

조회 수: 12 (최근 30일)
Warith Sheibany
Warith Sheibany 2017년 3월 23일
댓글: Warith Sheibany 2017년 3월 23일
I want to use an if statement that its condition depends on a variable to give the following conditions (<= or >=). For example:
if condiotion
a = '<=';
else
a = '>=';
end
if 4 a 9 %I want to use variable a to give the condition, this will minimize the size of my code
do something
end
I will appreciate your help Thanks.
  댓글 수: 2
KSSV
KSSV 2017년 3월 23일
Question is not clear..
Warith Sheibany
Warith Sheibany 2017년 3월 23일
I want to use a variable a that is assigned from previous if statement to choose either <= or >= for an if statement. for instance; if 3 a 7 should work as (if 3 <= 7 or 3 >= 7 )
I hope it is clear now?

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

채택된 답변

Guillaume
Guillaume 2017년 3월 23일
if somecondition
comparisonop = @le; %le is the function name for <=
else
comparisonop = @ge; %ge is the function name for >=
end
if comparisonop(4,9)
%do something
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by