MATLAB: How to create a matrix that represents the mean of every n days for every row

matrix

I have a matrix called T that is 3327×2 which represents the price of a share. I need to calculate into another matrix the mean of the last 90 days of the share price for every row. Lets say im in the cell 100×2, I need to calculate the mean of the last 90 days of the share price and so on for 101×2, 101×3,…
So I can get a matrix that is 3237×2 cause I cant calculate the mean of cell 1×1 of T(3327×2).

Best Answer

You need to use movmean(), Following code will compute mean with window size of 90 days.
T_mean = movmean(T, 90, 'Endpoints', 'discard'); % T is 3327 x 2
T_mean will be 3328x2.