Here is my code ( x- a sorted array):
lookup_value = 310.0
x = [298.0, 303.0, 308.0, 313.0, 323.0]
if (issorted(x))
idx = searchsorted(x, lookup_value)
end
In this particular case, the idx value is:
4:3
Here I would like to extract either "4" (the first element that exceeds my search value) or "3" (the last element that does not exceed my search value). However, I cannot do this by converting the range to an array, since all I get from the following command is an empty array:
julia> collect(idx)
0-element Array{Int64,1}
Note that the search value of 310.0 is just an example; this variable can take on different values.
source
share