We understand what a matrix multiply means. :) But it sounds like you don't appreciate the use of sparse matrices in MATLAB. Just because your matrix has zero elements in it, does not make it a matrix stored in sparse form.
If your sparse matrix is indeed stored in sparse format, then MATLAB will AUTOMATICALLY use highly efficient multiplication.
A = sprand(1000,1000,0.005);
B = sprand(1000,1000,0.005);
Af = full(A);
Bf = full(B);
whos A B Af Bf
Name Size Bytes Class Attributes
A 1000x1000 87656 double sparse
Af 1000x1000 8000000 double
B 1000x1000 87832 double sparse
Bf 1000x1000 8000000 double
But sparse matrices are not only there to save space. MATLAB does use the known sparsity in a multiplication.
timeit(@() Af*Bf)
ans =
0.078021563737
timeit(@() A*B)
ans =
0.000990737737
If you want something faster than the already fast multiplication built into MATLAB that works with sparse matrices, then, no. Not gonna happen.
Best Answer