How to efficiently calculate a weighted sum of 3 dimensional matrix through a vector in matlab
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
A is a 3 dimensional matrix (M*N*K), b is a vector with length K. I need to calculate
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1542397/image.png)
3 Commenti
Matt J
il 20 Nov 2023
@Hancheng Zhu If that means you've settled on one of the answers below, please Accept-click one of them.
Risposta accettata
Bruno Luong
il 17 Nov 2023
Modificato: Bruno Luong
il 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 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!