How to efficiently calculate a weighted sum of 3 dimensional matrix through a vector in matlab
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Matt J
2023년 11월 20일
@Hancheng Zhu If that means you've settled on one of the answers below, please Accept-click one of them.
채택된 답변
Bruno Luong
2023년 11월 17일
편집: Bruno Luong
2023년 11월 17일
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
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!