Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative of IF and "OR"

In this code (a,b,c,d,e,f,g,h,i,j) are variables):

if ( a>b || c>d || e==f || g<h || i!=j )
{
//Some statement; 
}

If one condition is true among the five, the if will be executed. However, my actual requirement is that if any three or more of these five conditions are true then if should be executed. In the actual code there may be more conditions (10 or more). How can I change the code to set a minimum number of true conditions? I am coding in MATLAB.

like image 980
ALI Avatar asked Feb 12 '23 05:02

ALI


1 Answers

You may sum up results of your comparisons and check sum against some number. For example:

if ( (a>b) + (c>d) + (e==f) + (g<h) + (i!=j) >= 3 )
like image 194
Alexey Shmalko Avatar answered Feb 15 '23 09:02

Alexey Shmalko