% M-script to calculate the mean
% of a vector X using while.
% X must exist before running this M-script
%
% AUTHORS: MB-AS-MG - 2010
Nelem=length(X);
meanX = 0;
index=1;
%calculate the X mean
while index <= Nelem; % while loop.
    meanX = meanX + X(index);
    index = index + 1; % counter updating
end
meanX = meanX / Nelem;
disp(sprintf('the X mean is %2.2f',meanX));