title: Using Java PriorityQueue in Matlab
body: <p>I need a min-heap in Matlab and I'm trying to use Java's PriorityQueue. I'm stuck on how to supply the Comparator.
  So far I have initialized the PriorityQueue and can add one value-index pair to it:</p>
  
  <pre><code>&gt;&gt; q = java.util.PriorityQueue
  q =
  []
  &gt;&gt; q.add({1,3})
  ans =
       1
  </code></pre>
  
  <p>The problem occurs when I try to add more data:</p>
  
  <pre><code>&gt;&gt; q.add({2,4})
  ??? Java exception occurred: 
  java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.Comparable
      at java.util.PriorityQueue.siftUpComparable(Unknown Source)
      at java.util.PriorityQueue.siftUp(Unknown Source)
      at java.util.PriorityQueue.offer(Unknown Source)
      at java.util.PriorityQueue.add(Unknown Source)
  </code></pre>
  
  <p>From <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/293430" rel="noreferrer">this</a> post, I see that I need to supply a Comparator function, but I don't know how to do this.</p>