How to us variable as an if statement condition?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Warith Sheibany
am 23 Mär. 2017
Kommentiert: Warith Sheibany
am 23 Mär. 2017
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 Kommentare
Akzeptierte Antwort
Guillaume
am 23 Mär. 2017
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!