www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/MovingVarianceOfVectorWithNaNElementsExample.m

    %% Moving Variance of Vector with |NaN| Elements
% Compute the three-point centered moving variance of a row
% vector containing two |NaN| elements.
A = [4 8 NaN -1 -2 -3 NaN 3 4 5];
M = movvar(A,3)

%%
% Recalculate the variance, but omit the |NaN| values.  When
% |movvar| discards |NaN| elements, it takes the variance over
% the remaining elements in the window.
M = movvar(A,3,'omitnan')