Effacer les filtres
Effacer les filtres

3D Matrix Multiplication

32 vues (au cours des 30 derniers jours)
Rahul Marwaha
Rahul Marwaha le 24 Fév 2021
Commenté : Masoud Aminzadeh le 6 Août 2023
Hi I have created two large matrices of which I have reshaped to create the following:
A = 3x1x4 double
B = 3x3x4 double
C = B * A ????
I was wondering how I could multiply each 3x3 matrix from B with each 3x1 matrix from A? The aim is to create a new 3x1x4 matrix in the end. Note: I don't have R2020b so don't have access to the pagemtimes function.
Any help is greatly appreciated, thanks!
  1 commentaire
Masoud Aminzadeh
Masoud Aminzadeh le 6 Août 2023
use pagewise function

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 24 Fév 2021
Modifié(e) : the cyclist le 24 Fév 2021
You can do it straightforwardly with a for loop:
% Some made-up input data
A = rand(3,1,4);
B = rand(3,3,4);
[mA,nA,pA] = size(A);
[mB,nB,pB] = size(B);
C = zeros(mB,nA,pA);
for np = 1:pA
C(:,:,np) = B(:,:,np) * A(:,:,np);
end
  1 commentaire
Rahul Marwaha
Rahul Marwaha le 25 Fév 2021
Thanks, that worked perfectly!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 24 Fév 2021

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by