That is extremely close to what I want. I notice that it does not error out though:
julia> A = zeros(5,5)
5×5 Matrix{Float64}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> nextind(A, CartesianIndex(4,1))
CartesianIndex(5, 1)
julia> nextind(A, CartesianIndex(4,1))
CartesianIndex(5, 1)
julia> nextind(A, CartesianIndex(5,5))
CartesianIndex(1, 6)
julia> nextind(A, CartesianIndex(5,6))
CartesianIndex(1, 7)
julia> nextind(A, CartesianIndex(5,7))
CartesianIndex(1, 8)
I would like it to throw nothing or return the same value when doing 5,5 since it is last element.
Kind regards