Array slicing in Julia differs a bit from Matlab.
In Matlab, everything is an array; even a scalar is a 1x1 array.
In Julia, there are distinct data types for scalars, vectors, AdjointVectors and Arrays.
This notebook illustrates how those differences affect array slicing.
For rationale, see the "Dimension sum slices" section under this blog:
https://julialang.org/blog/2016/10/julia-0.5-highlights
Jeff Fessler, University of Michigan
2017-07-24, original
2020-08-05, Julia 1.5.0
2021-08-23, Julia 1.6.2
A = [10*m+n for m=1:3, n=1:4] # start with a simple "self documenting" 2D array
3×4 Matrix{Int64}: 11 12 13 14 21 22 23 24 31 32 33 34
A[1:2,:] # slicing multiple rows or columns works the same as in Matlab
2×4 Matrix{Int64}: 11 12 13 14 21 22 23 24
A[2,:] # however, slicing a single row returns a 1D vector, not a 1×4 array!
4-element Vector{Int64}: 21 22 23 24
A[[2],:] # this unusual version of slicing a single row returns a 1×4 array!
1×4 Matrix{Int64}: 21 22 23 24
A[:,3] # slicing a single column yields a vector, NOT a 3×1 array
3-element Vector{Int64}: 13 23 33
A[[2],:] * A[[3],:]' # 1×4 array times a 4×1 array yields a 1×1 array!
1×1 Matrix{Int64}: 2930
A[:,[3]] # this way gives a 3×1 array, not a vector
3×1 Matrix{Int64}: 13 23 33
A[:,3]' * A[:,2] # dot product between Adjoint Vector and vector yields a scalar
1718
A[:,[3]]' * A[:,[2]] # 1×3 array times a 3×1 array yields a 1×1 array!
1×1 Matrix{Int64}: 1718
A[2,:] * A[3,:]' # this would be a dot product in Matlab
# but it is an outer product in Julia.
4×4 Matrix{Int64}: 651 672 693 714 682 704 726 748 713 736 759 782 744 768 792 816