When I type this error jumps in julia but I don't know why, it should be working./
julia> A = [1 2 3 4; 5 6 7 8; 1 2 3 4; 5 6 7 8]
4×4 Array{Int64,2}:
1 2 3 4
5 6 7 8
1 2 3 4
5 6 7 8
julia> B = A[2:1:end; 2:1:end]
ERROR: syntax: missing last argument in "2:1:" range expression
Stacktrace:
[1] top-level scope at REPL[9]:0

The syntax to index a multidimensional array uses a comma , instead of semicolon ; as separator between dimensions, see https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1. Thus you want to do:
julia> A = [1 2 3 4; 5 6 7 8; 1 2 3 4; 5 6 7 8]
4×4 Array{Int64,2}:
1 2 3 4
5 6 7 8
1 2 3 4
5 6 7 8
julia> B = A[2:1:end, 2:1:end]
3×3 Array{Int64,2}:
6 7 8
2 3 4
6 7 8
Note also that you can omit 1 in the range specification, as step 1 is the default:
julia> A[2:end, 2:end]
3×3 Array{Int64,2}:
6 7 8
2 3 4
6 7 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With