title: Fastest way to pick out data
body: <p>I am programming a function which should be able to integrate a function between a and b. The catch is that the function is only provided by a data array with corresponding time points. </p>
  
  <p>The problem is that when a lower and upper limit I have to cut out the part of the data vector that lies within this timeframe - and my question is, how is this done the most efficient? </p>
  
  <p>What I am doing now is the following:</p>
  
  <pre><code>llim = find(time==lima); 
  ulim = find(time==limb);
  
  data = data(llim:ulim); 
  int1 = h/2*(data(1) + data(end) + 2*sum(data(2:end))); 
  </code></pre>
  
  <p>But according to the profiler 50-something % are used on the first 3 lines, so if that could be reduced it would be great. </p>
  
  <p>I have also tried using </p>
  
  <pre><code>data = data(time&gt;=lima &amp; time&lt;=limb);
  </code></pre>
  
  <p>but that is not faster. Any suggestions?</p>