title: Shorter code in matlab to minimize data and getting corresponding indices
body: <p><strong>EDIT</strong> How to simplify the following code:</p>
  
  <pre><code>if(x(a) &gt; x(b))
    s = b;
    e = a;
  else
    s = a;
    e = b;
  end
  </code></pre>
  
  <p>I can get it shorter like:</p>
  
  <pre><code>s = a;
  e = b;
  if(x(a) &gt; x(b))
    s = b;
    e = a;
  end
  </code></pre>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>h = [a b]; 
  [~, idx] = min([x(a) x(b)]);
  s = h(idx)
  e = h(3-idx)
  </code></pre>