[英]How can I efficently use Matlab to find the all the variances along the third dimension of a 3D array?
If I have a matrix A of size nx * ny * nz
, I could find the variances I'm looking for by using a double for loop: 如果我有一个大小为nx * ny * nz
的矩阵A,我可以通过使用double for循环找到我正在寻找的差异:
varA = zeros(ny,nx);
for jj = 1:ny
for ii = 1:nx
varA(jj,ii) = var(A(jj,ii,:));
end
end
However, I would very much like to avoid using this loop, as it can take a long time for large arrays. 但是,我非常希望避免使用这个循环,因为大型数组可能需要很长时间。 Is there an easy way to do this calculation efficiently in Matlab? 有没有一种简单的方法可以在Matlab中有效地进行计算?
You want to provide the dim
input to var
to specify the dimension along which to apply the calculation. 您希望为var
提供dim
输入以指定应用计算的维度。
varA = var(A, 0, 3);
You must specify the weighting scheme (the second argument) to be the default (0). 您必须将加权方案(第二个参数)指定为默认值(0)。
NOTE : This dimension parameter is available for many simple calculations including
mean
,std
,diff
. 注意 :此维度参数可用于许多简单计算,包括mean
,std
,diff
。 Check the documentation for the specific function. 检查文档中的特定功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.