matlab - Multiplication of two arrays with dimension=5 in a vectorize way -
i have 3 dimensional domain in matlab. each point in domain have defined 3 arrays of size (nx,ny,nz)
@ each point of domain:
a1; % size(a1) = [nx ny nz] a2; % size(a2) = [nx ny nz] a3; % size(a3) = [nx ny nz]
for each element, trying construct array holds value of a1
, a2
, , a3
. following candidate having 1×3
vector @ each point?
b = [a1(:) a2(:) a3(:)]; b = reshape(b, [size(a1) 1 3]);
if 1×3
array named c
, trying find c'*c
@ each point.
c = [a1(i,j,k) a2(i,j,k) a3(i,j,k)]; % size(c) = [1 3] d = c'*c; % size(d) = [3 3]
my ultimate goal find array d
size 3×3
points in domain in vectorize fashion? in fact, output consists of array d each point have size [nx ny nz 3 3]
. me?
basically concatenate a1
, a2
, a3
along 4th , 5th dimensions separately leaves singleton dimensions in 5th , 4th dimensions respectively, used bsxfun
[apply element-by-element binary operation 2 arrays singleton expansion enable] expand 3x3 matrices
along 4th-5th dimensions matrix multiplication result each triplet of [a1(i,j,k),a2(i,j,k),a3(i,j,k)]
.
d = bsxfun(@times,cat(4,a1,a2,a3),cat(5,a1,a2,a3));
Comments
Post a Comment