www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ComputeMovingAverageOfVectorWithNaNElementsExample.m
%% Moving Average of Vector with |NaN| Elements % Compute the three-point centered moving average of a row % vector containing two |NaN| elements. A = [4 8 NaN -1 -2 -3 NaN 3 4 5]; M = movmean(A,3) %% % Recalculate the average, but omit the |NaN| values. When % |movmean| discards |NaN| elements, it takes the average over % the remaining elements in the window. M = movmean(A,3,'omitnan')