Note that logical indexing creates a temporary array (the vector saving the indices), potentially leading to slower than necessary code if they are created in a hot loop.
From the docs:
In MATLAB, an idiomatic way to remove unwanted values is to use logical indexing, like in the expression
x(x>3)
or in the statementx(x>3) = []
to modifyx
in-place. In contrast, Julia provides the higher order functionsfilter
andfilter!
, allowing users to writefilter(z->z>3, x)
andfilter!(z->z>3, x)
as alternatives to the corresponding transliterationsx[x.>3]
andx = x[x.>3]
. Usingfilter!
reduces the use of temporary arrays.
Since you seem to be iterating over the rows of the matrix, maybe you can tell us more about what you want to do with those logical indices?
Also, you can get the unique rows of your matrix by a simple call to unique
:
julia> A = vcat((a,b,a,a,a,a,b,b,b)...)
9×3 Array{Int64,2}:
1 2 3
3 4 5
1 2 3
1 2 3
1 2 3
1 2 3
3 4 5
3 4 5
3 4 5
julia> unique(A, dims=1)
2×3 Array{Int64,2}:
1 2 3
3 4 5