Arrays 在Matlab中,将存储在两个多维数组中的向量相乘,而不使用for循环?
我尝试了bsxfun,但找不到任何合适的操作。您可以将数组乘法与Arrays 在Matlab中,将存储在两个多维数组中的向量相乘,而不使用for循环?,arrays,matlab,multidimensional-array,Arrays,Matlab,Multidimensional Array,我尝试了bsxfun,但找不到任何合适的操作。您可以将数组乘法与bsxfun一起使用。 %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-l
bsxfun一起使用。
%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一起使用
%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);
这对我来说是新的。我看了两遍才知道发生了什么。很好,我穿新的。我看了两遍才知道发生了什么。很不错的。