Need help with Operands operators must be convertible to logical scalar values
1 view (last 30 days)
Show older comments
David Geistlinger
on 14 Nov 2018
Commented: madhan ravi
on 14 Nov 2018
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
0 Comments
Accepted Answer
madhan ravi
on 14 Nov 2018
Edited: madhan ravi
on 14 Nov 2018
use & instead of &&
2 Comments
Walter Roberson
on 14 Nov 2018
I think it is likely that you need to use logical indexing or a for loop.
More Answers (1)
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 .
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!