MatLab has the smoothdata function for calculating moving averages. At the edges it simply shortens the sample window and takes the average over the data available. I\'m trying