Need help with Operands operators must be convertible to logical scalar values

1 view (last 30 days)
Receving this error:
Operands to the || and && operators must be convertible to logical scalar values.
Error in DriverProgram (line 59)
if x2 >= 0 && x2 <= 8
{code}
if x2 >= 0 && x2 <= 8
x2_double_prime = (w-d)/m;
else
x2_double_prime= (w-d-b-r)/m;
end

Accepted Answer

madhan ravi
madhan ravi on 14 Nov 2018
Edited: madhan ravi on 14 Nov 2018
use & instead of &&

More Answers (1)

Walter Roberson
Walter Roberson on 14 Nov 2018
your x2 is not a scalar. You need to figure out whether it is an error in the code that permits the value to be empty or aa vector or array , or whatever you want the condition to trigger only if the condition is true for all of the values , or if you want the values to be examined individually .
If you want it to be true only if it is true for all values in x2 then change the && to & and consider using the all() function for clarity .
If you want the values to be examined individually then either use aa loop or else learn how to use logical indexing .

Products

Community Treasure Hunt

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

Start Hunting!