How to efficiently calculate a weighted sum of 3 dimensional matrix through a vector in matlab
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
A is a 3 dimensional matrix (M*N*K), b is a vector with length K. I need to calculate

3 commentaires
Matt J
le 20 Nov 2023
@Hancheng Zhu If that means you've settled on one of the answers below, please Accept-click one of them.
Réponse acceptée
Bruno Luong
le 17 Nov 2023
Modifié(e) : Bruno Luong
le 17 Nov 2023
This uses matrix multiplication so it should be well optimized and fast.
[m,n] = size(A, [1 2]);
C = reshape(A,m*n, []) * B(:);
C = reshape(C, m, n);
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Logical 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!