LoadError: MethodError: no method matching sub2ind( )

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(TotalN2,TotalN2)
TM_TOGL = zeros(TotalN2,TotalN2)

TM_NOOP[1:TotalN,1:TotalN] = TM_P[:,:]
TM_NOOP[TotalN+1:2TotalN,
TotalN+1:2
TotalN] = TM_EA[:,:]

TM_TOGL[1:TotalN,TotalN+1:2TotalN] = 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"

Please see PSA: how to quote code with backticks

Run it in v0.5 first to get the deprecations

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