So I have the following function
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
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
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.