B = randn(1,25,10);
Z = [1;1;1;2;2;3;4;4;4;3];好的,所以,我想找出Z=1(或任何相等于彼此的数字)的位置,然后在这些特定位置的25个点中每个点的平均值。在本例中,您将以1*25*4数组结尾。
有什么简单的方法吗?
我不是最精通Matlab的。
发布于 2014-10-14 09:50:48
首先要做的是:解决问题。
一旦您这样做,您可以开始看到它是一个相当标准的循环和“选择符合标准的列”。
与…有关的东西:
B = randn(1,25,10);
Z = [1;1;1;2;2;3;4;4;4;3];
groups = unique(Z); %//find the set of groups
C = nan(1,25,length(groups)); %//predefine the output space for efficiency
for gi = 1:length(groups) %//for each group
idx = Z == groups(gi); %//find it's members
C(:,:,gi) = mean(B(:,:,idx), 3); %//select and mean across the third dimension
end发布于 2014-10-14 09:55:19
如果是B = randn(10,25);,那就很容易了,因为Matlab函数通常是向下工作的。
使用逻辑索引:
ind = Z == 1;
mean(B(ind,:));如果您正在处理多个维度,请使用permute (如果实际有三维或更多维度,则使用reshape )使自己达到如下所示的平均行数:
B = randn(1,25,10);
BB = permute(B, [3,2,1])继续如上
https://stackoverflow.com/questions/26357093
复制相似问题