Search code examples
matlabmatrixmatrix-indexing

Matrix Indexing with larger matrix


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!


Solution

  • 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.