Reputation: 235
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
Reputation: 112659
This is one approach:
[ii, jj] = find(D==1);
result = sum(A(ii,:).'.*B(:,jj), 1);
Upvotes: 3