在矢量方式两个阵列与尺寸= 5的乘法 [英] Multiplication of two arrays with dimension=5 in a vectorize way

查看:98
本文介绍了在矢量方式两个阵列与尺寸= 5的乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB三维域。对于域中的每个点我定义大小的三个数组(NX,NY,NZ)在域的每个点:

I have a three dimensional domain in MATLAB. For each point in the domain I have defined three arrays of size (NX,NY,NZ) at each point of the domain:

A1; % size(A1) = [NX NY NZ]
A2; % size(A2) = [NX NY NZ]
A3; % size(A3) = [NX NY NZ]

对于每一个元素,我要建持有 A1 A2 ,和值的数组 A3 。将下面是有一个一个很好的候选人1×每点3 矢量?

For each element, I am trying to construct an array which holds the value of A1, A2, and A3. Would the following be a good candidate for having a 1×3 vector at each point?

B = [A1(:) A2(:) A3(:)];
B = reshape(B, [size(A1) 1 3]);

如果在 1×3 数组被命名为 C ,我试图找到 C'* C 在每个点。

If the 1×3 array is named C, I am trying to find C'*C at 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]

我的最终目标是找到数组 D 与大小 3×3 在域中的所有点在矢量时尚?事实上,它由阵列的D每个点的输出将具有大小 [NX纽约NZ 3 3] 。可能有人帮助我吗?

My ultimate goal is to find the array D with size 3×3 for all the points in the domain in a vectorize fashion? In fact, the output which consists of array D for each point will have the size [NX NY NZ 3 3]. Could someone help me?

推荐答案

基本上,我们串连 A1 A2 A3 沿着第四和第五分别尺寸留下分别在第5和第4的尺寸单维度,然后再使用的 bsxfun [应用元素乘元素的二进制操作两个阵列与单扩展启用的]扩大,因为 3×3的矩阵沿的每个三重矩阵乘法结果的4至5尺寸[ A1(I,J,K),A 2(I,J,K),A 3(I,J,K)]

Basically we concatenate A1, A2 and A3 along the 4th and 5th dimensions separately that leaves singleton dimensions in the 5th and 4th dimensions respectively, which are then used by bsxfun [Apply element-by-element binary operation to two arrays with singleton expansion enable] to expand as 3x3 matrices along the 4th-5th dimensions for matrix multiplication result from 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));

这篇关于在矢量方式两个阵列与尺寸= 5的乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆