Dot produkt MxNxL -Array with a L-element vector

I have an array with MxNxL elements and I want to do a vector multiplication of every M,N element with a L-element vector so that I end up with a MxNx1 array that has the scalar product of each element array with the vector. Do you know how I can do this without having to do two loops over M and N in order to get the scalar products?
My slow solution looks like
For m= 1:M
For n=1:N
As (m,n,1)=dot(A(m,n,1:3),B(1:3))
End
End

 採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 24 日

0 投票

m = size(A,1);
k = 3;
As = reshape(reshape(permute(A(:,:,1:k),[3,1,2]),k,[])'*reshape(B(1:k),[],1),m,[]);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAerospace Blockset についてさらに検索

質問済み:

2017 年 11 月 24 日

回答済み:

2017 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by