calculate a vector from consecutive vectors without a loop
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi
I would like to receive the mean value of each 10 consecutive values of a vector. Is it possible to run it without a for loop?
Using a for it would have been:
for ix=1:length(X)-9 mean_X = mean(X(ix:ix+9)) end
Thanks Guy
0 Commenti
Risposta accettata
Kye Taylor
il 12 Giu 2013
Modificato: Kye Taylor
il 12 Giu 2013
Totally.. try something like
yourVector = 1:100;
avgWindow = 1/10*ones(1,10); % each value is 1/10
movingAverage = conv(yourVector,avgWindow,'valid')
Compare with
for i = 1:numel(yourVector)-9
movingAverageLoop(i) = mean(yourVector(i:i+9));
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!