function y = vmean(x,nx,nanflag)
%MATLAB Code Generation Private Function

%   y = mean(x(1:nx),nanflag)
%   Used in movmean and movvar to avoid variable sizing.

%   Copyright 2002-2016 The MathWorks, Inc.
%#codegen

coder.internal.prefer_const(nx,nanflag);
identity = zeros('like',sum(coder.internal.scalarEg(x)));
ONE = coder.internal.indexInt(1);
omitnan = nanflag(1) == 'o';
[y,count] = combineVectorElements(@plus,x(:),identity,ONE,omitnan,nx);
y = y/cast(count,'like',y);

