I have a NxNx4 matrix(A) and a 4x4 matrix (B). I need to multiply the vector a composed by the four elements of the first matrix A, let's say
a = A(1,1,1)
A(1,1,2)
A(1,1,3)
A(1,1,4)
by the 4x4 matrix B but I'm not sure if there is a faster and clever solution than using a for loop to build the vector a. Does exist a way to do this computation with few lines of code?
I built A like
A(:,:,1) = rand(20);
A(:,:,2) = rand(20);
A(:,:,3) = rand(20);
A(:,:,4) = rand(20);
and the matrix B
B = rand(4);
now I want to multiply B with
B*[A(1,1,1);A(1,1,2);A(1,1,3);A(1,1,4)]
This, for each element of A
B*[A(1,2,1);A(1,2,2);A(1,2,3);A(1,2,4)]
B*[A(1,3,1);A(1,3,2);A(1,3,3);A(1,3,4)]
...
N*N*4matrix, and a4*4matrix, and your exampleais neither! Please show a minimal reproducible example of your expected input / output, this sounds relatively easy if it were well defined, but at present it's unclear. - Wolfie4*1vector, I guess your expected outputCis a matrix the same size asA? - WolfieCis supposed to be again an NxNx4 matrix. I'm choosing the multidimensional matrix instead of 4 separate matrix to be able to compute the classical multiplication matrix-vectorB*a- Shika93bsxfun(@times, ...)or something more advanced likemmxormtimesx. - Dev-iL