# How to find indices like Matlab

**URL:** <https://discourse.julialang.org/t/how-to-find-indices-like-matlab/68639>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 23, 2021, 5:42pm UTC](https://discourse.julialang.org/t/how-to-find-indices-like-matlab/68639 "2021-09-23T17:42:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [September 23, 2021, 5:42pm UTC](https://discourse.julialang.org/t/how-to-find-indices-like-matlab/68639/1 "2021-09-23T17:42:11Z")

</div>

For example, I have a matrix A as below:  
`A = [1, 2, 3; 4, 3, 8; 12, 2, 5; 7 , 4, 9];`

So its first column would be like this:  
1  
4  
12  
7

How do I find the rows with the first column \>6? In Matlab I can do the below:  
B = A(A(:,1)\>6, :);

How do I do that in Julia?

I tried to get the index by doing  
Ind = A[:,1]\>6;

and got the below error:

```julia
MethodError: no method matching isless(::Int64, ::Vector{Float64})
Closest candidates are:
  isless(::AbstractVector{T} where T, ::AbstractVector{T} where T) at abstractarray.jl:1989
  isless(::Any, ::Missing) at missing.jl:88
  isless(::Missing, ::Any) at missing.jl:87
  ...

Stacktrace:
 [1] <(x::Int64, y::Vector{Float64})
   @ Base ./operators.jl:279
 [2] >(x::Vector{Float64}, y::Int64)
   @ Base ./operators.jl:305
 [3] top-level scope
   @ In[5]:1
 [4] eval
   @ ./boot.jl:360 [inlined]
 [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116

```

Many thanks!

---

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [September 23, 2021, 5:50pm UTC](https://discourse.julialang.org/t/how-to-find-indices-like-matlab/68639/2 "2021-09-23T17:50:15Z")

</div>

Here you go!

```julia
julia> A = [1 2 3;4 5 6;7 8 9]
3×3 Matrix{Int64}:
 1 2 3
 4 5 6
 7 8 9

julia> A .> 6
3×3 BitMatrix:
 0 0 0
 0 0 0
 1 1 1

julia> A[A .> 6]
3-element Vector{Int64}:
 7
 8
 9

```

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [September 23, 2021, 5:50pm UTC](https://discourse.julialang.org/t/how-to-find-indices-like-matlab/68639/3 "2021-09-23T17:50:47Z")

</div>

Welcome to Julia Discourse!

Comparisons in Julia are not automatically applied elementwise, unlike in MATLAB. In Julia, just add a dot:

```julia
julia> A = [1 2 3; 4 3 8; 12 2 5; 7 4 9];

julia> ind = A[:,1] .> 6
4-element BitVector:
 0
 0
 1
 1

julia> A[ind,:]
2×3 Matrix{Int64}:
 12 2 5
  7 4 9

```

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [September 23, 2021, 6:09pm UTC](https://discourse.julialang.org/t/how-to-find-indices-like-matlab/68639/4 "2021-09-23T18:09:13Z")

</div>

Many thanks for the solution! This will serve my purpose well.

I am a brand new Julia user and really appreciate your kind help.
