How to increment CartesianIndex?

Depends on what you mean by “increment”, but you can also use nextind to get the next (consecutive) index in a given array:

julia> A = rand(5,5);

julia> nextind(A, CartesianIndex(3,1))
CartesianIndex(4, 1)

(Better documentation for this was recently merged: Document the generic functions nextind() and prevind() by JamesWrigley · Pull Request #52658 · JuliaLang/julia · GitHub)

5 Likes