nabla
nabla

Reputation: 235

Sparse multiplication, MATLAB: only certain elements

Is there any built-in or efficient way to calculate only certain elements in a matrix multiplication A*B = C in MATLAB? For example, calculate only the elements of C, (i,j) such that D(i,j) = 1, for some other matrix.

Upvotes: 1

Views: 47

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

This is one approach:

[ii, jj] = find(D==1);
result = sum(A(ii,:).'.*B(:,jj), 1);

Upvotes: 3

Related Questions