2

I'm trying to understand some old code from a predecessor and I'm having some problems with a certain kind of matrix indexing:

I have a large matrix A that has labelled regions (neighboring elements that share a number) Now I have a second matrix B=[0 1 2 3 ... n] with n being the number of elements Then we access output = B(A+1).
Now I don't really get what happens when I try to index a smaller matrix with a larger one. And then I don't see that output is any different from my matrix A.

Anybody can help me with my confusion? Thanks!

Shai
  • 111,146
  • 38
  • 238
  • 371
DarkCell
  • 170
  • 1
  • 11

1 Answers1

0

Indexing a small vector using a large matrix is a (nice) way of performing a look-up-table operation: that is output is generated by replacing each element of A by the element B(A+1) the result is the same size as A.
In your particular example, since B( A(ii,jj)+1 ) == A(ii,jj) for all ii and jj, this specific look-up operation is meaningless.

You can try different B vectors and see how that change influence output.

Shai
  • 111,146
  • 38
  • 238
  • 371
  • Ah thanks. Can you explain what Matlab is actually doing when I index a smaller vector with a larger matrix? – DarkCell Dec 03 '14 at 15:54
  • @DarkCell the result of `B(A+1)` assigns, for each element of `A`, the output `B(A(ii,jj)+1)`. the output is thus of size `A`. – Shai Dec 03 '14 at 16:57