# ERROR: LoadError: UndefRefError: access to undefined reference

**URL:** https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683
**Category:** General Usage
**Created:** [January 23, 2020, 5:21am UTC](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683 "2020-01-23T05:21:19Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![natgeo-wong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/natgeo-wong/32/10965_2.png) [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)
#### Post date: [January 23, 2020, 5:21am UTC](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683/1 "2020-01-23T05:21:19Z")

</div>

So I have the following function

```julia
function regionextract(data::Array{<:Real},coord::Array)

    nlon1 = length(coord[1]); nlon2 = size(data,1);
    nlat1 = length(coord[2]); nlat2 = size(data,2);
    nt = size(data)[3:end]; ndim = ndims(data);

    if ndim == 2; data = data[coord[1],coord[2]];
    elseif ndim >= 3;
        data = reshape(data,nlon2,nlat2,:);
        data = data[coord[1],coord[2],:];
        data = reshape(data,Tuple(vcat(nlon1,nlat1,nt...)));
    end

end

```

However, I have the following error

```julia
ERROR: LoadError: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex at ./array.jl:729 [inlined]
 [2] macro expansion at ./multidimensional.jl:699 [inlined]
 [3] macro expansion at ./cartesian.jl:64 [inlined]
 [4] macro expansion at ./multidimensional.jl:694 [inlined]
 [5] _unsafe_getindex! at ./multidimensional.jl:690 [inlined]
 [6] _unsafe_getindex(::IndexLinear, ::Array{Real,3}, ::UnitRange{Int64}, ::UnitRange{Int64}, ::Base.Slice{Base.OneTo{Int64}}) at ./multidimensional.jl:684
 [7] _getindex at ./multidimensional.jl:670 [inlined]
 [8] getindex at ./abstractarray.jl:981 [inlined]

```

which I have traced to the line

```julia
data = data[coord[1],coord[2],:];

```

I’ve seen other topics with the same error, but I am not sure if I am doing my types correctly. I’ve checked on both `coord[1]` and `coord[2]` and they both give reasonable values that are within the bounds of the `data` array.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [January 23, 2020, 6:44am UTC](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683/2 "2020-01-23T06:44:00Z")

</div>

It is very likely that you have not initialized elements of `coord`, but it is hard to say more without a [self-contained example](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757). Cf

```julia
julia> Array{Any}(undef, 1)[1]
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex(::Array{Any,1}, ::Int64) at ./array.jl:787
 [2] top-level scope at REPL[1]:1

```

---

<div class="post-metadata">

### Author: ![natgeo-wong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/natgeo-wong/32/10965_2.png) [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)
#### Post date: [January 23, 2020, 7:01am UTC](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683/3 "2020-01-23T07:01:03Z")

</div>

What do you mean exactly by coord not being initialized?

`coord[1]` and `coord[2]` both exist: doing `@info coord[1]` gives me `345:456`, for example.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [January 23, 2020, 8:17am UTC](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683/4 "2020-01-23T08:17:14Z")

</div>

I was just guessing based on the information you provided. Again, it is hard to say more without an MWE.

---

<div class="post-metadata">

### Author: ![natgeo-wong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/natgeo-wong/32/10965_2.png) [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)
#### Post date: [January 24, 2020, 5:59pm UTC](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683/5 "2020-01-24T17:59:41Z")

</div>

Update. Seems to be that I defined things in the parent function wrongly 😑 so yeah, I think this topic can be closed haha.
