本文介绍了通过一个三维阵列循环找到平均值和标准偏差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有一个数组< 134x106x108>。我想要做的就是遍历这个数组,平均/标准偏差存储到另一个数组。因此,基本上会有134 LT; 106x108双打>,将在此meanArray和sdArray。

 %dayv =< 134x106x108>
 sdArray =零(1106108);
 meanArray =零(1106108);
对于i = 1:尺寸(dayv,1)
    店内%意味着/标准差到一个数组
    meanArray(I,:,:) =挤压(平均(dayv(I,:,:)));
    sdArray(I,:,:) =挤压(STD(dayv(I,:,:)));
结束


解决方案

如果您希望您的每一个手段,是整个106x108矩阵的平均再一个简单的解决方案是使用,重塑您的3D矩阵为二维矩阵

  dayv2 =重塑(dayv,[134 106 * 108]);

现在每个那些106x108矩阵是在新的矩阵的行向量。

然后

  meanArray =平均(dayv2,2); %获得平均每行
stdArray = STD(dayv2,0,2);每行的标准%

Ok so I have an array <134x106x108>. What I'm trying to do is loop through this array and store the average/standard deviation into another array. So basically there will be 134 <106x108 doubles> that will be in this meanArray and sdArray.

 %dayv=<134x106x108>
 sdArray=zeros(1,106,108);
 meanArray=zeros(1,106,108);
for i=1:size(dayv,1)
    %store means/standard deviation into an array
    meanArray(i,:,:) = squeeze(mean(dayv(i,:,:)));
    sdArray(i,:,:) = squeeze(std(dayv(i,:,:)));
end
解决方案

If you want each of your means to be the average of an entire 106x108 matrix then one easy solution is to reshape your 3d matrix into a 2d matrix using,

dayv2 = reshape(dayv,[134 106*108]);

Now each of those 106x108 matrices is a row vector in your new matrix.

Then

meanArray = mean(dayv2,2); % Get mean of each row
stdArray  = std(dayv2,0,2);% Std of each row

这篇关于通过一个三维阵列循环找到平均值和标准偏差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 07:10