ind .= CartesianIndex.(getindex.(ind, 1) .- 1, getindex.(ind, 2))
or equivalently
@. ind = CartesianIndex(getindex(ind, 1) - 1, getindex(ind, 2))
which gives
julia> mat[ind]
2-element Vector{Int64}:
1
2
Two problems: your ind_ready() function actually decrements the second index (with A[:,2] = A[:,2] .- 1 ), not the first, resulting in invalid 0 indices:
julia> i2 = ind_ready()
2-element Vector{CartesianIndex}:
CartesianIndex(2, 0)
CartesianIndex(2, 1)
Second, Julia doesn’t like that your ind_ready returns an abstractly typed CartesianIndex[] vector and not a concretely typed CartesianIndex{2}[] vector:
julia> mat[CartesianIndex[CartesianIndex(1,1)]]
ERROR: ArgumentError: unable to check bounds for indices of type CartesianIndex{2}
julia> mat[CartesianIndex{2}[CartesianIndex(1,1)]]
1-element Vector{Int64}:
1
But this error message is confusing and should be fixed: confusing error for array[CartesianIndex[...]] indexing · Issue #48655 · JuliaLang/julia · GitHub