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.
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With