I have a matrix of size 64500x17. It represents detected texton features that I have to use to find 5 centroids for kmeans.
What I need is:
Just use indexing and store the extracted matrices in cells for easier handling:
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
you can then join these means with:
joined_means = cell2mat(splitted_data_means);
Or just for the heck-of-it with the one-liner:
joined_means = cell2mat(arrayfun(@(ii) mean(data((ii-1)*12900+(1:12900),:)),(1:5)','uni',false));
which would be even simpler with @angainor's mat2cell:
joined_means = cell2mat(cellfun(@mean,mat2cell(data, 12900*ones(5,1), 17),'uni',false));