四维数组与二维数组相乘。

有一个数据A 格式是x*y*z*t
相当于经度、维度、高度、时间维
有一个数组B,格式是x*y,经度*维度
现在要对数组A 每一个网格平面与数组B相乘
我只会下面这种循环切片的方式,效率很低,请问有别的方法吗?
for iz = 1z
for it = 1 : t
       C(:,:,iz,it) = squueze(A(:,:,iz,it)) .* B
end
end
%--------更新
目前想到一个方法,把数组B 复制扩充 ,这样数组A和数组B规格相同,直接矩阵相乘可
B0 = repmat(B, [1,1,z,t]);
C  = A.* B0

 Accepted Answer

doocon
doocon on 15 May 2023

0 votes

2020b 开始的版本使用 pagemtimes 函数:
Z = pagemtimes(X,Y)
帮助文档:如果 X 或 Y 之一是矩阵,则 pagemtimes 将其与另一输入的每页相乘。例如,如果 X 是矩阵,则 Z(:,:,i) = X*Y(:,:,i)。

More Answers (0)

Categories

Find more on 矩阵和数组 in Help Center and File Exchange

Tags

Asked:

on 15 May 2023

Answered:

on 15 May 2023

Community Treasure Hunt

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

Start Hunting!