%In MATLAB: I have stored vectors A and B in two multidim. arrays:
A = rand(4,1,4); B= rand(1,3,4);
%Now I want to create multidim array C(3,3,4)
%by multiply A and B in each dim i (:,:,i) without a for-loop.
%So instead of these four operations below, just perform one operation e.g. C=A*B.
C(:,:,1)=A(:,:,1)*B(:,:,1);
C(:,:,2)=A(:,:,2)*B(:,:,2);
C(:,:,3)=A(:,:,3)*B(:,:,3);
C(:,:,4)=A(:,:,4)*B(:,:,4);
我尝试了bsxfun,但找不到合适的操作。
答案 0 :(得分:2)
您可以将数组乘以bsxfun
C = bsxfun(@times,A,B)