• Register
0 votes
446 views

Problem :

I have very simple problem that currently looking for the fast implementation in Matlab. I have below array of values:

 b = floor(rand(5,5).*255)

I also have the similarly sized threshold array :

b_thresh = floor(rand(5,5).*255)

I want to use the value of b unaltered. I thought I can use something like the below:

b(b>= b_thresh .* 0.4 && b <b_thresh.* 0.5) = ((b - b_thresh.*0.4)/(b_thresh.*0.5 b_thresh.*0.4)) .* b;

But, I am facing below error :

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

How can I resolve the issue?

7.5k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Regarding your first problem : The thing about the && is that it can operate only on the scalars, whereas the & can operate on arrays as well. So you should change your && to & to make it work.
 

Now regarding your second problem : The number of the elements on your left is different because you are trying to use the indices and on your right you are trying to work with the entire matrix b and b_thresh.

So you need to use the indices in both sides, so I suggest you to store it in the variable and then use it as the array subscript, along below lines:

myidx = (b >= b_thresh*0.4 & b < b_thresh*0.5);
b(myidx) = ((b(myidx)-b_thresh(myidx)*0.4) ./ (b_thresh(myidx)*0.5*b_thresh(myidx)*0.4)) .* b(myidx);

I hope it solves your issue.

38.6k points

Related questions

0 votes
1 answer 39 views
39 views
Problem: What could be the problem > Operands to the || and && operators must be convertible to logical scalar values. matlab
asked Apr 24 ummeshani 10.8k points
0 votes
1 answer 116 views
116 views
Problem: I am stuck with this ... Please help me that how to deal with this error? operands to the and && operators must be convertible to logical scalar values. matlab
asked Mar 23 Ifra 43.4k points
0 votes
1 answer 16 views
16 views
Problem: whitePixels=ext_rows((150<ext_rows) && (ext_rows<200)); numberWhitePixels=numel(whitePixels); error : Operands to the || and && operators must be convertible to logical scalar values. How can I solve this error? Could you please write down the correct code here?
asked Apr 25 Moumita Bhowmick 12.9k points
0 votes
1 answer 9 views
9 views
Problem: Operands to the and && operators must be convertible
asked Jun 28 Hridoy 19.2k points
1 vote
1 answer 19 views
19 views
Problem: I am facing this problem on Mtlab please resolve it: Matlab operands to the and operators must be convertible.
asked Apr 27 PkGuy 25.9k points
0 votes
1 answer 183 views
183 views
Problem: Do you have any thoughts on how bitwise operators cannot be utilized on the float type? Thank you so much!
asked Mar 31 zayed1 61.8k points
0 votes
1 answer 28 views
28 views
Problem: Why would a language NOT use Short-circuit evaluation? Are there any benefits of not using it? I see that it could lead to some performances issues... is that true? Why?
asked Apr 23 nabin 5.1k points
0 votes
1 answer 23 views
23 views
Problem: Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
asked Apr 8 nabin shrestha 4.7k points
0 votes
1 answer 653 views
653 views
Problem: Hello programmers! I am learning to program, and I just got a little confused about boolean values and logical operators. I tried to run the following program: #include<iostream> using namespace std; int main() { bool check = false && true || true; ... program, I got the following output: Condition evaluated to true I am so confused about how this condition evaluates to true. Any help?
asked Dec 18, 2020 Code Learner 10.5k points
0 votes
1 answer 148 views
148 views
Problem: I am learning logical operators in C# and I came across &,&& and |, ||. I am confused about what is the difference in both of these representations?
asked Oct 15, 2020 Code Learner 10.5k points