title: MATLAB: compute mean of each 1-minute interval of a time-series
body: <p>I have a bunch of times-series each described by two components, a timestamp vector (in seconds), and a vector of values measured. The time vector is non-uniform (i.e. sampled at non-regular intervals)</p>
  
  <p>I am trying to compute the mean/SD of each 1-minutes interval of values (take X minute interval, compute its mean, take the next interval, ...).</p>
  
  <p>My current implementation uses loops. This is a sample of what I have so far:</p>
  
  <pre><code>t = (100:999)' + rand(900,1);       %' non-uniform time
  x = 5*rand(900,1) + 10;             % x(i) is the value at time t(i)
  
  interval = 1;         % 1-min interval
  tt = ( floor(t(1)):interval*60:ceil(t(end)) )';  %' stopping points of each interval
  N = length(tt)-1;
  
  mu = zeros(N,1);
  sd = zeros(N,1);
  
  for i=1:N
      indices = ( tt(i) &lt;= t &amp; t &lt; tt(i+1) ); % find t between tt(i) and tt(i+1)
      mu(i) = mean( x(indices) );
      sd(i) = std( x(indices) );
  end
  </code></pre>
  
  <p>I am wondering if there a faster vectorized solution. This is important because I have a large number of time-series to process each much longer than the sample shown above..</p>
  
  <p>Any help is welcome.</p>
  
  <hr>
  
  <p>Thank you all for the feedback.</p>
  
  <p>I corrected the way <code>t</code> is generated to be always monotonically increasing (sorted), this was not really an issue..</p>
  
  <p>Also, I may not have stated this clearly but my intention was to have a solution for any interval length in minutes (1-min was just an example)</p>