. Advertisement .

..3..

. Advertisement .

..4..

I get the error: “operands to the || and && operators must be convertible to logical scalar values” when I try to run the program below:

```
a = floor(rand(5,5).*255)
a_thresh = floor(rand(5,5).*255)
a(a < a_thresh.*0.4) = 0
a(a > a_thresh.*1.2) = 0
a(a>= a_thresh .* 0.4 && a <a_thresh.* 0.5) = ((a - a_thresh.*0.4)/(a_thresh.*0.5 a_thresh.*0.4)) .* a;
```

The error appears the system notifies as follows:

`Operands to || and && operations must be convertible to logical scalar values`

I tried to solve it with another sample. I got the reference in the community forum, but it still returned an invalid result. If someone knows the solution, please give me the support. Thanks!

There are two types of logical operators that can be used for certain functions in matlab.

For example, you can utilize or && as well as & to operate on scalers. To logically compare vectors (which is performed by comparing each element) it is necessary to make use of the operator &.

If you are trying to determine whether two vectors are equivalent then use the function isequal(a,b) instead of. The same uses for | |.

Regarding your second problem described in a comment: the number of elements on the left is different because you’re using indices (selecting only certain features). You’re working with the entire matrix a and a_thresh on the right. It would help if you used indices on both sides, so I suggest storing it in a variable and then using it as an array subscript, along these lines: