只需使用索引并将提取的矩阵存储在单元格中以便于处理:
data = rand(64500,17);
Nsubsets = 5;
Nsubsize = size(data,1)/Nsubsets;
splitted_data = cell(Nsubsets ,1);
splitted_data_means = cell(Nsubsets,1);
for ii=1:Nsubsets
splitted_data{ii} = data((ii-1)*Nsubsize + (1:Nsubsize),:);
splitted_data_means{ii} = mean(splitted_data{ii});
end
然后,您可以通过以下方式加入这些方式:
joined_means = cell2mat(splitted_data_means);
或者只是为了使用单线:
joined_means = cell2mat(arrayfun(@(ii) mean(data((ii-1)*12900+(1:12900),:)),(1:5)','uni',false));
使用@angainor's 会更简单mat2cell
:
joined_means = cell2mat(cellfun(@mean,mat2cell(data, 12900*ones(5,1), 17),'uni',false));