SubArrays should let you do this.

julia> x = 1:5
1:5

julia> y = sub(x, 4:8)
5-element SubArray{Int64,1,UnitRange{Int64},(UnitRange{Int64},)}:
   4   
   5   
 #undef
 #undef
 #undef

julia> y[0]
3

julia> y[-2]
1

julia> y[2]
5

--Tim

On Tuesday, August 25, 2015 10:57:50 AM Sven Duve wrote:
> Hello,
> 
> I am on Julia 0.3.9, I am trying to implement an American Binomial Spread
> Options model. I got it working, but am wondering if there is a different
> solution, perhaps cleaner one.
> 
> I am doing the following to populate the options value's array, and then
> loop over the array to simulate the exercise conditions in the tree:
> 
> 
>   for i in range(N-1, -1, N)   ## the outer loop is counting down walking
> back in the tree
>     for j in range(-i, 2, i+1)
>       for k in range(-i, 2, i+1)
> 
>              C[k+(N+1), j+(N+1)] = "some value" ## so in order to position
> the value to the right location in the Array, I need to adjust the index
> with (N+1)
> 
>         end
>     end
>   end
> 
> 
> The question really is, can I create a matrix and change the indexing like
> A = eye(), so that when A[0, 0] would be the center of the matrix?
> 
> 
> Thanks
> 
> 
> Sven

Reply via email to