function [mea, varargout] = statTwo( x,varargin )
 
% The function returns the mean and the standard deviation 
% on the element of x eventually selected by i.
%
% INPUT:    x vector of numbers. Do not use with matrices.
%           i vector of logicals. 
% OUTPUT:   mea = is the mean 
%           if required by the number of outputs, the 
%           second element is a cell variable containing the 
%           variance.    
% Author:   Borgo, Soranzo, Grassi 2010

disp(sprintf('Number of input: %d',nargin)); 
disp(sprintf('Number of output: %d',nargout)); 
i=logical(ones(size(x)));
if nargin == 2 
   i = logical(varargin{1});
end
Nelem = sum(i);
mea=sum(x(i))/Nelem;
if nargout == 2
    varargout{1}=sum(x(i).^2)/Nelem;
end