average every sets of rows
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
I have a 1629 by 1 matrix, and I wish to average every n rows, and place in a new matrix.

where n = 1629.
For this example, the arrays are averaged every 7 rows.
My aim is to have a function which tells matlab to average every k rows, where k can be 7 as in the diagram above, but k can be other values too. So, I won't be telling matlab how many rows will be in the final matrix.
If anyone has an explanation on how to tackle this, please let me know.
I have been trying a double for loop,
so
for n=1:size(meanE,1); % mean E is the matrix above, with 1629 rows
for v=n:n+1/res %1/res is the increment, in the example above, it is 7
meanF=mean(meanE,'all') %trying to calculate the average between the set rows
meanF=meanF(); %trying to place the average of each set rows in a new array
end
end
Please help me understand. I started learning matlab a few weeks ago, and any help will be very much appreciated.
Kind regards,
Anshul
0 commentaires
Réponse acceptée
David Hill
le 21 Nov 2022
a=20*rand(1629,1);
k=7;
e=floor(length(a)/k)*k;
r=reshape(a(1:e),k,[]);
M=mean(r)
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!