%% Moving MAD of Vector with NaN Elements
% Compute the three-point centered moving MAD of a row vector containing two NaN elements.

A = [2 1 NaN -1 -2 -3 NaN 3 4 1];
M = movmad(A,3)

%
% Recalculate the moving MAD omitting the NaN values. When movmad discards NaN elements, it computes over the remaining elements in the window.

M = movmad(A,3,'omitnan')

% Copyright 2012 The MathWorks, Inc.