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!

1 Answer 1

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.

2
  • Ah thanks. Can you explain what Matlab is actually doing when I index a smaller vector with a larger matrix?
    – DarkCell
    Dec 3, 2014 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 3, 2014 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.