Thanks Greg, seems like in this case y has to be a column vector else you
get an error:
julia> y
1x2 Array{Int64,2}:
1 2
julia> i = sub2ind(size(a), 1:2, y)
ERROR: MethodError: `sub2ind` has no method matching
sub2ind(::Tuple{Int64,Int64}, ::UnitRange{Int64}, ::Array{Int64,2})
You might have used a 2d row vector where a 1d column vector was required.
Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2
3].
You can convert to a column vector with the vec() function.
Closest candidates are:
sub2ind{T<:Integer}(::Tuple{Vararg{Integer}},
::AbstractArray{T<:Integer,1}...)
sub2ind(::Tuple{Vararg{Integer}})
sub2ind(::Tuple{Vararg{Integer}}, ::Integer...)
julia> y = [1,2]
2-element Array{Int64,1}:
1
2
julia> i = sub2ind(size(a), 1:2, y)
2-element Array{Int64,1}:
1
4
On Saturday, December 19, 2015 at 11:51:11 PM UTC-8, Greg Plowman wrote:
>
> I'm guessing you want y to specify a column from each row.
> Not sure how to do this directly. Closest I can think of this:
>
> a = [ -1 2; 3 -4 ]
> y = [ 1, 2 ]
> i = sub2ind(size(a), 1:2, y)
> a[i]
>
>