#  LoadError: MethodError: no method matching sub2ind( )

**URL:** <https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-sub2ind/13154>\
**Category:** New to Julia\
**Created:** [August 10, 2018, 6:56am UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-sub2ind/13154 "2018-08-10T06:56:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelord12](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@marcelord12](https://discourse.julialang.org/u/marcelord12)\
**Post date:** [August 10, 2018, 6:56am UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-sub2ind/13154/1 "2018-08-10T06:56:30Z")

</div>

Hi Guys

I’m trying to run these two scripts below on Julia 0.6.4 and ATOM1.29. These scripts were written on Julia 0.4.5 and have some parts of the syntax that are outdated.  
As I’m not familiar with Julia, I’m not sure what changes I have to implement on the function sub2ind(feat\_size,feat\_ind) to solve the LoadError: MethodError: no method matching sub2ind( )

Can somebody help?

===============================  
LoadError: LoadError: e[91mMethodError: no method matching sub2ind()e[0m

Closest candidates are:

sub2ind(e[91m::Tuple{}e[39m) at abstractarray.jl:1563  
sub2ind(e[91m::Tuple{}e[39m, e[91m::Integer…e[39m) at abstractarray.jl:1566  
sub2ind(e[91m::AbstractArraye[39m, e[91m::Any…e[39m) at abstractarray.jl:1538  
…e[39m

# while loading /Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/Takeoff/Abstraction.jl, in expression starting on line 2 while loading /Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/Takeoff/Run.jl, in expression starting on line 4 include\_from\_node1(::String) at loading.jl:576 include(::String) at sysimg.jl:14 include\_string(::String, ::String) at loading.jl:522 include\_string(::Module, ::String, ::String) at Compat.jl:88 (::Atom.##112#116{String,String})() at eval.jl:109 withpath(::Atom.##112#116{String,String}, ::String) at utils.jl:30 withpath(::Function, ::String) at eval.jl:38 hideprompt(::Atom.##111#115{String,String}) at repl.jl:67 macro expansion at eval.jl:106 [inlined] (::Atom.##110#114{Dict{String,Any}})() at task.jl:80

"using JLD2

include(“MonteCarlo.jl”)  
include(“Abstraction.jl”)  
include(“PlotMCSim.jl”)

# Run Monte carlo trials with pilot

RunMCSim(1)  
save(“./PilotData.jld2”,“X”,X,“U”,U,“D”,D,“Tend”,Tend)

#PlotSim()  
GetTransMat!(X,U,D,Tend,TM\_P)

# Run Monte carlo trials with envelope-aware controlle

RunMCSim(2)  
save(“./EAData.jld2”,“X”,X,“U”,U,“D”,D,“Tend”,Tend)

#for i=1:trials  
#PlotSim(i)  
#end

GetTransMat!(X,U,D,Tend,TM\_EA)

#===============================================  
Use Pilot and Envelope-aware transition matrices  
to construct transition matrices for actions  
NOOP and TOGL  
===============================================#

TM\_NOOP = zeros(TotalN_2,TotalN_2)  
TM\_TOGL = zeros(TotalN_2,TotalN_2)

TM\_NOOP[1:TotalN,1:TotalN] = TM\_P[:,:]  
TM\_NOOP[TotalN+1:2_TotalN,  
TotalN+1:2_TotalN] = TM\_EA[:,:]

TM\_TOGL[1:TotalN,TotalN+1:2_TotalN] = TM\_EA[:,:]  
TM\_TOGL[TotalN+1:2_TotalN,1:TotalN] = TM\_P[:,:]

writedlm(“TensorNOOP.txt”,TM\_NOOP)  
writedlm(“TensorTOGL.txt”,TM\_TOGL)"

"import Base: sub2ind, ind2sub

function sub2ind(feat\_size,feat\_ind)

```
#================================================================
Get the single index corresponding to the feature indices given
================================================================#

total_feat = length(feat_ind)

index = 0

for i in range(1,total_feat)
    if i < total_feat
        index = index + (feat_ind[i]-1) * prod(feat_size[i+1:end])
    else
        index = index + (feat_ind[i]-1)
    end
end

return (index+1)

```

end

function ind2sub(feat\_size,index)

```
#================================================================
Get the feature indices corresponding to the given index
================================================================#

last = length(feat_size);

subscripts = zeros(Int,length(feat_size))

index = index - 1

while last>=1
    subscripts[last] = (index % feat_size[last]) + 1
    index = floor(Int,index / feat_size[last])
    last = last - 1;
end

return subscripts

```

end

# V-X Envelope parametrization

VXmodel(X,params) = params[1] + params[2].\*X + params[3].\*X.^2 +  
params[4].\*X.^3

function AbstractVX(V,X)

```
xenv1 = VXmodel(V,VXparams[:,1])
xenv2 = VXmodel(V,VXparams[:,2])
xenv3 = VXmodel(V,VXparams[:,3])

if 0 <= V < Vef0
    if X <= xenv1
        vx = 1
    elseif X > xenv1 && X <= X_V1
        vx = 8
    elseif X > X_V1 && X <= xenv2
        vx = 10
    elseif X > xenv2 && X <= Rmax
        vx = 12
    elseif X > Rmax
        vx = 15
    end
elseif Vef0 <= V < V1
    if X <= xenv3
        vx = 3
    elseif X > xenv3 && X <= xenv1
        vx = 2
    elseif X > xenv1 && X <= X_V1
        vx = 9
    elseif X > X_V1 && X <= xenv2
        vx = 11
    elseif X > xenv2 && X <= Rmax
        vx = 13
    elseif X > Rmax
        vx = 15
    end
elseif V1 <= V < max(V2,Vab0)
    if X <= xenv2
        vx = 4
    elseif X > xenv2 && X <= X_V1
        vx = 5
    elseif X > X_V1 && X < xenv3
        vx = 6
    elseif X > xenv3 && X < Rmax
        vx = 14
    elseif X > Rmax && X > xenv3
        vx = 16
    end
elseif V > max(V2,Vab0)
    vx = 7
else
    vx = 18
end

```

end

function AbstractPH(P,H)

```
if H < H_TS
    if P_1 <= P < P_2
        ph = 1
    elseif P_2 <= P < P_3
        ph = 2
    elseif P_3 <= P < P_4
        ph = 3
    elseif P >= P_4
        ph = 4
    end
else
    if P_1 <= P < P_2
        ph = 5
    elseif P_2 <= P < P_3
        ph = 6
    elseif P_3 <= P < P_4
        ph = 7
    elseif P >= P_4
        ph = 8
    end
end

```

end

function Abstraction(X,U,D)  
#=================================================================  
Abstraction(X,U,D)  
Inputs:  
\* X - Aircraft state vector  
\* U - Control input vector  
\* D - Discrete variables  
Output:  
\* Function returns the discrete state index corresponding to  
the given continuous state and control input  
=================================================================#

```
d2r = π/180
r2d = 180/π

p = X[4]*r2d
q = X[5]*r2d
r = X[6]*r2d
ϕ = X[7]*r2d
θ = X[8]*r2d
ψ = X[9]*r2d
d = X[10]
y = X[11]
h = X[12]
V = X[13]

T = U[4]

eng = D[1]

# Abstract VX
vxs = AbstractVX(V,d)

# Abstract PH
phs = AbstractPH(θ,h)

# Abstract T
if T< 0.1
    ts = 1
else
    ts = 2
end

# Abstract Engine
if eng == 2
    es = 3
elseif eng == 1
    es = 2
else
    es = 1
end

# Find discrete state
dis_state = sub2ind(FeatSize,[vxs,phs,ts,es])

return dis_state

```

end

function GetTransMat!(X,U,D,Tend,TM)  
#=================================================================  
Estimates the transition probability matrix given the data.  
=================================================================#

```
Trials = size(X,3)

for i=1:Trials
    tf = round(Int,Tend[i])

    for j=1:tf-1

        s1 = Abstraction(X[j,:,i],U[j,:,i],D[j,:,i])
        s2 = Abstraction(X[j+1,:,i],U[j+1,:,i],D[j+1,:,i])

        if ( s1 != s2 )
            TM[s1,s2] = TM[s1,s2] + 1
        end

    end
end

# Normalize matrix
for i=1:TotalN
    row_sum = sum(TM[i,:])
    if row_sum > 0
        TM[i,:] = TM[i,:]/row_sum
    end
end

```

end"

---

<div class="post-metadata">

**Author:** ![crbinz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crbinz/32/1919_2.png) [@crbinz](https://discourse.julialang.org/u/crbinz)\
**Post date:** [August 10, 2018, 6:34pm UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-sub2ind/13154/2 "2018-08-10T18:34:09Z")

</div>

Please see [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [August 10, 2018, 7:29pm UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-sub2ind/13154/3 "2018-08-10T19:29:05Z")

</div>

Run it in v0.5 first to get the deprecations

---

<div class="post-metadata">

**Author:** ![marcelord12](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@marcelord12](https://discourse.julialang.org/u/marcelord12)\
**Post date:** [August 11, 2018, 2:22am UTC](https://discourse.julialang.org/t/loaderror-methoderror-no-method-matching-sub2ind/13154/4 "2018-08-11T02:22:10Z")

</div>

I’m trying to do it now on Julia 0.4.7 and I’m getting error to install JLD , HDF5 and homebrew.
