How to filter a tuple by the first element

First you need to obtain an array marking the elements that you want, and then use that array to index the arrays (you have three independent arrays, and the fact that they are in a tuple does not help much):

julia> data = (rand(5),rand(5));

julia> inds = data[1] .> 0.5 # bool array
5-element BitVector:
 0
 1
 1
 1
 1

julia> data[2][inds]
4-element Vector{Float64}:
 0.3156756681271574
 0.3046881119816406
 0.6945063237653067
 0.8492254807551606

julia> plot(data[1][inds],data[2][inds])

A least general way, if the data[1] is always increasing, is to use something like:

julia> data = (sort(rand(5)),rand(5));

julia> data[1]
5-element Vector{Float64}:
 0.03852598530448814
 0.18616226772164635
 0.25586337027799577
 0.3970926196952723
 0.8350821471218625

julia> i = findfirst(x -> x > 0.2, data[1])
3

julia> plot(data[1][i:end],data[2][i:end])

(or if it is just plotting what you want, adjust the xlims of the plot)

1 Like