Using vectorization to compute moving average in Matlab -


i wrote script compute simple moving average of vector using for-loop:

x=rand(1000,1);  y=nan(size(a)); i=100:length(a);     y(i)=mean(x(i-99:i)); end 

could use vectorization method avoid loop? thanks.

you can avoid loop using either convolution (conv) or smooth if have curve fitting toolbox.

filtersize = 5; y = conv(x, ones(1, filtersize) / filtersize, 'same');  % or curve-fitting toolbox y = smooth(x, filtersize); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -