x =[2 3 4 5 6 7 8] z = [2 6 5] y= indexin(z,x)
is there a built in function to sort the results of indexin
x =[2 3 4 5 6 7 8] z = [2 6 5] y= indexin(z,x)
is there a built in function to sort the results of indexin
The problem here is that you start with (1,n) matrices x and z:
julia> x =[2 3 4 5 6 7 8]
1Ă—7 Matrix{Int64}:
2 3 4 5 6 7 8
which results in the end, that indexin
returns 2-dimensional indices:
julia> y[2]
CartesianIndex(1, 5)
where order isn’t defined per default so you can’t use sort!
on y
.
If indexin
would provide a “return sorted indices” parameter, the problem would be same that no order is defined.
So the question is: is it mandatory, that you are dealing with
1Ă—7 Matrix{Int64}
? Or tis this just some oversight? If you actually have vectors, it would be straight forward:
julia> z = [2, 6, 5]
3-element Vector{Int64}:
2
6
5
julia> y= indexin(z,x)
3-element Vector{Union{Nothing, Int64}}:
1
5
4
julia> y= sort(indexin(z,x))
3-element Vector{Union{Nothing, Int64}}:
1
4
5
You can reshape your matrices with:
julia> x =[2 3 4 5 6 7 8]
1Ă—7 Matrix{Int64}:
2 3 4 5 6 7 8
julia> x = reshape([2 3 4 5 6 7 8],length(x))
7-element Vector{Int64}:
2
3
4
5
6
7
8
thanks!!! worked