MATLAB: How to multiplay matrices in different dimensions matricesmultiple I would like to multiply a 3D matrice with a 2D matrice. Best Answer Perhaps:a = rand(2,2,3);b = [2, 2; 4, 4]% Elementwise - auto-expanding since R2016b:r = a .* b% Matrix multiplication:r = zeros(2, 2, 3);for k = 1:3 r(:, :, k) = a(:, :, k) * b;endIf the later is wanted, you can vectorize the code or use some tools from the FileExchange to avoid the loop. Related SolutionsMATLAB: What is the matrix multiplication of these two vectors To do matrix multiplication the inner dimensions must agree. Both of your matrices are 1x5 vectors. You can do either of the following:A' * B (results in a 5x5 matrix)orA * B' (results in a 1x1 scalar) MATLAB: Multiplay without * using for loop log Related Question“Kronecker” of varying dimensionsElementwise Multiplication of column of 3D-array with an 1D-array
Best Answer