matlab - Multiply tensor with vector -
A = ones (4,4,4); B = [1,2,3,4]; I want to multiply this way with A,
ans (:,:, 1) == ones (4,4) * B (1); ans (:,:, 2) == ones (4,4) * b (2); etc.
I think you are looking for:
A = ones (4,4,4); B = 1: 4; C = Schiedidium (B, -1); Bsxfun (@bar, A, C) Shiftdim ensures that the vector is placed in the correct dimension. Then bsxfun ensures that the vector is expanded to match the matrix, after which they can be properly multiplied. If you struggle to understand this function, then you should allow this result as a loop on the institutions of b .
Comments
Post a Comment