How can I calculate the products of a vector of matrices
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Suppose that I have an array like this:
mats=zeros(2,2,3);
mats(:,:,1)=[0.9 0.1;0.6 0.4];
mats(:,:,2)=[0.8 0.2;0.5 0.5];
mats(:,:,3)=[0.75 0.25;0.7 0.3];
(in my actual application the third dimension of this array is much larger than 3).
I am in need of a function which will produce the same result as the operations shown below:
mats2=zeros(2,2,3);
mats2(:,:,1)=mats(:,:,1);
mats2(:,:,2)=mats(:,:,1)*mats(:,:,2);
mats2(:,:,3)=mats(:,:,1)*mats(:,:,2)*mats(:,:,3);
This needs to be done without looping over the 3rd dimension of "mats" as doing so every time I need this result calculated would be extremely time-consuming.
In essence I am hence in need of a version of the prod()-function which will perform matrix multiplication successively over the elements (=matrices) of a vector of matrices and will store the results in a new vector of the same dimensions.
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!