Problem: suppose we want to apply say an averaging filter on a list of numbers. Say we want to replace each value in the list by the average 3 values around each value (a smoothing filter).
In Mathematica, ListConvolve is used, in Matlab conv() is used.
Mathematica data={1,2,7,9,3,4,10,12}; filter=(1/3){1,1,1}; data[[2;;-2]]=ListConvolve[filter,data]; N[data]
|
Out[66]= {1., 3.33333, 6., 6.33333, 5.33333, 5.66667, 8.66667, 12.} |
Matlab data = [1 2 7 9 3 4 10 12]; filter = (1/3)*[1 1 1]; data(2:end-1) = conv(data,filter,'valid'); data'
|
1.0000 3.3333 6.0000 6.3333 5.3333 5.6667 8.6667 12.0000 |