title: Matlab Maximum recursion limit of 500 reached error
body: <p>Hey I am new at Matlab and I wrote a simple code for quicksort but for some arrays mostly longer arrays my recursion fails and gives me the following error:
  "Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the
  limit. Be aware that exceeding your available stack space can crash MATLAB and/or
  your computer.</p>
  
  <p>Error in quic"</p>
  
  <p>I think my base case might be wrong but I can't figure out what I am doing wrong. Some help would be greatly appreciated. </p>
  
  <pre><code>function A = quicksort(A,left,right)
  
  
  [A, pivot] = PartitionPivot(A, left, right); %chosen pivot
  A = quicksort(A, left, pivot-1); %scan from the left of the array until an element greater than pivot is found and swap it with the element less than the pivot on the right of the pivot
  A = quicksort(A, pivot+1, right); %scan from the right of the array until an element less than   pivot is found and swap it with the element greater than the pivot on the left of the pivot
  end
  
  function [sortedSub_array,Pivot] = PartitionPivot(Sub_array,left_index,right_index)
  
  % Initialization
  S = Sub_array;
  left = left_index;
  right = right_index;
  
  P = S(left); %pivot
  i = left+1;
  
  % Partition
  for j = i:right 
      if S(j) &lt; P 
          temp1 = S(j);
          S(j) = S(i);
          S(i) = temp1;
          i = i+1; %increment i only when swap occurs
      end
  end
  swap1 = S(left);
  S(left) = S(i-1);
  S(i-1) = swap1;
  
  sortedSub_array = S;
  Pivot = P;
  </code></pre>