Matrix multiplication between 2d matrix and slice of 3d array

조회 수: 4 (최근 30일)
Morten Nissov
Morten Nissov 2019년 12월 27일
답변: Athul Prakash 2020년 1월 1일
I have two matrices A (3,3,x) and B (3,3) where x is a variable, known value and typically on the order of thousands. I need to compute the matrix multiplication of these two, I know this can be done by
function [ out ] = mat_mult( A,B )
[~,~,np] = size(A);
out = zeros(size(A));
for i=1:np
out(:,:,i) = A(:,:,i)*B;
end
end
but I figure there is a more efficient way to do this than for loops, especially for MATLAB. Unforunately, I am not quite sure how to vectorize this.

채택된 답변

Athul Prakash
Athul Prakash 2020년 1월 1일
Hey Morten,
You can check out 'MULTIPROD' - from File Exchange (linked below). It covers your requirements exactly,
( Please note that tools available on File Exchange are provided by the community and not created by Mathworks. The Mathworks does not provide any guarantees for such tools.)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by