# Indexing vector elements of a matrix

**URL:** <https://discourse.julialang.org/t/indexing-vector-elements-of-a-matrix/60631>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 6, 2021, 8:29am UTC](https://discourse.julialang.org/t/indexing-vector-elements-of-a-matrix/60631 "2021-05-06T08:29:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simcha/32/20726_2.png) [@Simcha](https://discourse.julialang.org/u/Simcha)\
**Post date:** [May 6, 2021, 8:29am UTC](https://discourse.julialang.org/t/indexing-vector-elements-of-a-matrix/60631/1 "2021-05-06T08:29:03Z")

</div>

I can’t seem to access all elements of equal index in a matrix in an intuitive way.  
What I have is a matrix of vectors “scan”  
Matrix{Vector{Float64}} (alias for Array{Array{Float64, 1}, 2})  
Accessing all elements of the vectors of equal index k in the way that makes sense:  
“scan[:,:][k]” does not work, while “[scan[x,y][113] for x=1:64, y=1:64]” does, but is really cumbersome.  
What am I missing?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [May 6, 2021, 8:37am UTC](https://discourse.julialang.org/t/indexing-vector-elements-of-a-matrix/60631/2 "2021-05-06T08:37:39Z")

</div>

```julia
julia> m=reshape( [rand(1:10,3) for i in 1:9] ,3,3)
3×3 Matrix{Vector{Int64}}:
 [3, 1, 5] [5, 5, 10] [6, 6, 5]
 [10, 3, 3] [9, 4, 6] [7, 8, 3]
 [4, 7, 9] [5, 7, 5] [4, 7, 1]

julia> getindex.(m,2) #get all values with index 2
3×3 Matrix{Int64}:
 1 5 6
 3 4 8
 7 7 7

```

Is a bit less cumbersome.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [May 6, 2021, 8:39am UTC](https://discourse.julialang.org/t/indexing-vector-elements-of-a-matrix/60631/3 "2021-05-06T08:39:29Z")

</div>

And by the way: Welcome!  
Always provide MWE (minimal working example), thats makes it much easier to comprehend the question 🙂  
See [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)
