First the general stuff: end
is just a placeholder for an index, namely the last position in a given array dimension. For instance, for an arbitrary array A(end,1)
will pick the last element in column 1, and A(1,end)
will pick the last element in the first row.
In your example, A(end, end-2)
picks an element in the last row two columns before the last one.
To interpret a statement such as
A(2:end, end:-2:1)
it might help to substitute end
with the actual index of the last row/column elements, so this is equivalent to
A(2:3, 4:-2:1)
Furthermore 4:-2:1
is equivalent to the list 4,2
since we are instructing to make the list starting at 4, decreasing in steps of 2, up to (minimum) 1. So this is equivalent to
A([2 3],[4 2])
Finally, the following combination of indices is implied by A([2 3],[4 2])
:
A(2,4) A(2,2)
A(3,4) A(3,2)