How to multiplay matrices in different dimensions?
107 次查看(过去 30 天)
显示 更早的评论
I would like to multiply a 3D matrice with a 2D matrice.
1 个评论
Jan
2019-6-6
Then do this. Remember that this operation is not defined mathematically, so you have to explain which result you want. Do you mean a matrix multiplication, or an elementwise product?
采纳的回答
Jan
2019-6-6
编辑:Jan
2019-6-6
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;
end
If the later is wanted, you can vectorize the code or use some tools from the FileExchange to avoid the loop.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!