Effacer les filtres
Effacer les filtres

Average of the Vector elements in the matrix

1 vue (au cours des 30 derniers jours)
Jab
Jab le 16 Sep 2015
Modifié(e) : Kirby Fears le 16 Sep 2015
I have a matrix of 815*440 and I need to take the average of every 20 elements in all the rows and find the output as 815*22
Any help is appreciated
Thanks
  3 commentaires
Jab
Jab le 16 Sep 2015
I am trying to do your second option
Kirby Fears
Kirby Fears le 16 Sep 2015
Modifié(e) : Kirby Fears le 16 Sep 2015
The answer I posted below solves that problem. Please give it a try.

Connectez-vous pour commenter.

Réponse acceptée

Kirby Fears
Kirby Fears le 16 Sep 2015
Modifié(e) : Kirby Fears le 16 Sep 2015
Below is a loop to take the mean of the first 20 columns, then the next 20 columns, etc. Let me know if this is not the computation you were trying to perform.
% Creating dummy matrix for example solution
a=reshape(1:815*440,815,440);
% Width of column groupings
colgroup=20;
% Initialize mean results array
results=NaN(size(a,1),size(a,2)/colgroup);
% Take means in loop
for iter=1:size(results,2),
startcol=colgroup*(iter-1)+1;
results(:,iter)=mean(a(:,startcol:startcol+colgroup-1),2);
end,

Plus de réponses (1)

James Tursa
James Tursa le 16 Sep 2015
Modifié(e) : James Tursa le 16 Sep 2015
Assuming you are averaging every 20 elements, not a sliding window:
A = your 815 x 440 matrix
m = mean(reshape(A',20,[]));
Anew = reshape(m,22,[])';

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by