I think this will be work:

julia> r = ones(5, 5)
5x5 Array{Float64,2}:
 1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0

julia> pos = [3, 4]
2-element Array{Int64,1}:
 3
 4

julia> r[pos...]
1.0

 — John

On Feb 17, 2014, at 4:58 PM, David P. Sanders <[email protected]> wrote:

> 
> 
> 
> El lunes, 17 de febrero de 2014 18:57:10 UTC-6, David P. Sanders escribió:
> Hi,
> 
> Suppose I have the following:
> 
> r = rand(5, 5)
> 
> I can select a single element of the array r using
> 
> r[3, 4]
> 
> Now suppose that I have the position [3, 4] stored in a variable as
> 
> pos = [3, 4]
> 
> How can I use pos as the index for selecting the *single* element r[3, 4]?
> 
> Of course, one solution is
> 
> r[pos[1], pos[2]]
> 
> but this is not suitable for a multi-dimensional array.
> 
> 
>  
> I would like to do r[pos], but this returns a *two*-element array, given by 
> the elements numbered 3 and 4 in the linear ordering of the array r.
> 
> This sounds like a silly question, but I can't find the answer!
> 
> 
> Thanks,
> David.

Reply via email to