title: Indexing equal/different elements in each row of a Matlab array
body: <p>Suppose I have a <code>IxJ</code> matrix <code>A</code> in Matlab which contains some numbers (possibly, including <code>Inf</code>, <code>-Inf</code>).</p>
  <p>For example, for <code>I=3</code> and <code>J=6</code>, I could have</p>
  <pre><code>A=  [0    0      Inf -Inf 0   1; 
       5    4      Inf -Inf 6   5;
       Inf -Inf    0    Inf 0   2];
  </code></pre>
  <p>I want to construct a matrix <code>B</code> of size <code>IxJ</code>, such that each row <code>i</code> starts from <code>1</code>, adds a <code>+1</code> every time an element of <code>A(i,:)</code> changes, and assigns equal index to equal elements. Two <code>Inf</code> elements have to be treated as equal. Similarly, two <code>-Inf</code> elements have to be treated as equal.</p>
  <p>In the example above</p>
  <pre><code>B=  [1 1 2 3 1 4;  %
       1 2 3 4 5 1;
       1 2 3 1 3 4];
  </code></pre>
  <p>Could you advise on how to proceed?</p>