Grouping Data Into Smaller "Bins"

1 vue (au cours des 30 derniers jours)
Nikitas Provatakis
Nikitas Provatakis le 12 Déc 2018
Modifié(e) : Jan le 12 Déc 2018
Hi everyone,
I have a matrix G containing a number of data points (say 5000 for the sake of this example). I would like to create a new matrix, K consisting of only 50 elements, so that every element is the average of the corresponding 100 elements in matrix G.
For example the third element of K should be the mean of elements 100 to 150 of G.
Any way to quickly do that?

Réponse acceptée

Jan
Jan le 12 Déc 2018
Modifié(e) : Jan le 12 Déc 2018
G = rand(5000, 3); % "data points" is not clear
N = 100;
siz = size(G);
GG = reshape(G, [N, siz(1)/N, siz(2)]);
R = reshape(sum(GG, 1) / N, siz(1)/N, siz(2));
If the length of the first dimension is not a multiple of N, you might want to crop the input at first.
R = BlockMean(G, N, 1) / N;

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by