How to multiplay matrices in different dimensions?

I would like to multiply a 3D matrice with a 2D matrice.

댓글 수: 1

Jan
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
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개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2019년 6월 6일

댓글:

2019년 6월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by