title: Truncating an array
body: <p>A simplified version of my code is as follows:</p>
  
  <pre><code>A = linspace(0,10,100);
  threshold = 6.0;
  </code></pre>
  
  <p>I'd like to truncate the vector A at values below the threshold value.</p>
  
  <p>Assuming that the values in A are always ascending, how can I do this neatly and efficiently?</p>
  
  <p>Currently the only method I can think of is to introduce a for-loop and examine each element, one after another and if it has a value above the threshold, and then to allocate this value to a new array. Something like this:</p>
  
  <pre><code>    k=1;
      for i = 1:numel(A)
          if A(i) &lt; threshold
          elseif A(i) &gt;= threshold
              Atrunc(k,1) = A(i);
              k=k+1;
          end
      end 
  </code></pre>
  
  <p>However this doesn't seem very 'nice' to me, can anybody offer more optimized code...?</p>