0

Consider the following 2 matrices: A = 3x3x3 and B = 3x3. Is it possible to perform an element wise multiplication between each slice of A and the kernel B without using a for loop? My current implementation is as follows:

for i = 1:3
    C = A(:,:,i) .* B(:,:);
end

where C is some output matrix

Jeremy Borg
  • 413
  • 2
  • 6
  • 16

1 Answers1

2

As @Divakar suggested, bsxfun did the trick:

C = bsxfun(@times, A, B);
Jeremy Borg
  • 413
  • 2
  • 6
  • 16