Can't multiply sparse logical matrices?

2 views (last 30 days)
Nachiketa Sahoo
Nachiketa Sahoo on 13 Jun 2012
Edited: Thomas Richner on 12 Dec 2017
Is there a way to multiply sparse logical matrices? I guess I am looking for a space efficient way to multiply matrices that contain only 0/1?
>> m = magic(5)
m =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> a = m>5
a =
1 1 0 1 1
1 0 1 1 1
0 1 1 1 1
1 1 1 1 0
1 1 1 0 1
>> b = m>10
b =
1 1 0 0 1
1 0 0 1 1
0 0 1 1 1
0 1 1 1 0
1 1 1 0 0
>> a+b
ans =
2 2 0 1 2
2 0 1 2 2
0 1 2 2 2
1 2 2 2 0
2 2 2 0 1
>> a*b
Error using *
Both logical inputs must be scalar.
To compute elementwise TIMES, use TIMES (.*) instead.

Answers (2)

the cyclist
the cyclist on 13 Jun 2012
The short answer is "no". However ...
I asked about multiplication of logical matrices a while back. There were some answers that might be helpful to you in the thread:

Thomas Richner
Thomas Richner on 12 Dec 2017
Edited: Thomas Richner on 12 Dec 2017
I too would love to multiply sparse logical matrices. I was completely surprised it wasn't implemented. The solution is to convert the smaller matrix to a sparse double with double(). Also note that sparse singles don't exist. I imagine as Matlab tries to keep pace with Deep Learning, they will need to add sparse singles, sparse logical multiplication, and half precision types.

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!