Lets look at how this works. So firstly when you index A by D, D gets flattened so A(D) = v is the same as A(D(:)) = v (test it!) and

D(:)
ans =
8
6
4
2
7
5
3
1

So for breaking it down element by element we're going A(D(1)) = v(1) which after substituting for D(1) and v(1) is A(8) = 10, hence the last element is 10. Lets look a few elements further. A(D(4)) = v(4) become A(2) = 40. but which element is A(2)? Well linear indexing counts down the rows first (column major ordering) i.e.