Matrix multiplication with logical values error
18 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Massimo Zanetti
2016 年 10 月 31 日
編集済み: Massimo Zanetti
2016 年 10 月 31 日
For logical matrices matrix multiplication doesn't apply (because it is not logical operation). To get your Dyadic product, cast to double:
dyd = double(I)*double(J)
NOTE: matrix product is not fully supported for integer classes in MATLAB, so casting to integer types (to save memory) won't work too..
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!