On Sun, 2014-02-23 at 05:51, [email protected] wrote:
> El viernes, 21 de febrero de 2014 08:25:00 UTC-6, Mauro escribió:
>>
>> > Given a matrix, which will be large (say 10^5 x 10^5), I need to extract
>> > the list of indices (i.e. the pairs (x,y) of positions) of those places
>> in
>> > the matrix
>> > where the value stored satisfies a certain condition. For a minimal
>> > example, the condition can just be that the value is greater than 0.5.
>>
>> Give you a logical array which you can use for indexing:
>> r.>.5
>> and to get the linear indices
>> find(r.>.5)
>>
>
> Great, didn't know about find.
> Maybe I should just rewrite everything thinking in terms of 1D arrays.
> (This is something I have taught in several courses,
> but for some reason it didn't occur to me!)
No need to rewrite in terms of 1D arrays. You can index both with a
linear index or with a 2D index (or higher D, depending on the array):
julia> a = [1 2; 3 4]
2x2 Array{Int64,2}:
1 2
3 4
julia> a[2]
3
julia> a[2,1]
3
If you want to translate between the two use ind2sub and sub2ind:
julia> ind = ind2sub(size(a), 2)
(2,1)
julia> a[ind...]
3