function y = cummean(x,dim)
   // Gets the cummulative mean of a signal
   //
   // Usage:
   //        y = cummean(x, dim)
   // where
   //        x:   a signal vector or array
   //        dim: dimension along which the cummulative
   //             mean is to be computed   
   //        y:   cummulative mean of x
   //
   // NOTE: If dim is not given, its default value ies 
   //       the first non-singleton dimension. Care
   //       should be taken when x is s multichannel
   //       signal where each row is a channel, since
   //       if dim is not specified the cummulative
   //       mean is computed column-wise.  
   //
   // -------------------------------
   // Author: Federico Miyara
   // Date:   2021-08-08
   
   // For testing purposes --DELETE--
   if 1==2
      caso = 1
      select caso
      case 2
         x = 1:1000000;
      case 2
         x = 1 + 0.3*rand(1,10000, "normal");
      case 2
         x = zeros(5,3,2)
         x(:,:,1) = [1:5; ones(1,5); 5:9]'
         x(:,:,2) = 2*[1:5; ones(1,5); 5:9]'
      end
   end
   
   rhs = argn(2);
   if rhs<2
      // If dim is not provided, select it as
      // the first non-singleton dimension   
      dim = 1
      for i=1:length(size(x))
         if size(x,i)~=1
            dim = i
            break;
         end
      end
   end
  
   // Compute cummulative mean along dimension dim
   y = cumsum(x, dim)./(1:size(x, dim));

endfunction
