Matrix multiplication with logical values error
Show older comments
I have this matrix:
M =
0 3 0 0
0 2 0 0
2 0 3 4
0 4 0 2
And I call these vectors:
I=~(any(3==M'))', J=~any(3==M)
I =
0
1
0
1
J =
1 0 0 1
Why I cant multiplicate "I*J"? And how can I fix it?
I*J
Error using *
Both logical inputs must be scalar.
To compute elementwise TIMES, use TIMES (.*) instead.
I want this result:
ans =
0 0 0 0
1 0 0 1
0 0 0 0
1 0 0 1
Thanks
Accepted Answer
More Answers (1)
Hans Ruder
on 11 Jun 2025
Alternatively, you can simply do:
dyd = I & J
Then the result will keep the logical data type.
Categories
Find more on Logical 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!