# Error in method definition: function Base.sub2ind must be explicated imported

**URL:** <https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133>\
**Category:** New to Julia\
**Created:** [August 10, 2018, 12:34am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133 "2018-08-10T00:34:07Z")\
**Posts on this page:** 11\
**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, 12:34am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/1 "2018-08-10T00:34:07Z")

</div>

Goode evening  
I’m not familiar with Julia programming and I’m trying to run the code below that was made on Julia 0.4.5. I got two errors messages. I’m working on Julia 0.6.4 - Atom 1.29\> I suppose I have to import something but I don’t know how the syntax should be. Can Somebody help?

Error in method definition: function Base.sub2ind must be explicited imported to be extended  
Error in method definition: function Base.ind2sub must be explicited imported to be extended

unction 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

---

<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, 3:01am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/2 "2018-08-10T03:01:22Z")

</div>

`import Base: sub2ind, ind2sub`

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 10, 2018, 11:03pm UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/3 "2018-08-10T23:03:52Z")

</div>

Please [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) and copy and paste full error messages precisely.

---

<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:07am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/4 "2018-08-11T02:07:45Z")

</div>

Thanks. It works, but I got a new different error when I execute the script Run.jl

LoadError: UndefVarError: save not definede

while loading /Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/Takeoff/Run.jl, in expression starting on line 10

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

==============

---

<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:08am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/5 "2018-08-11T02:08:07Z")

</div>

Here is the code of script Run.jl

‘’'using JLD2

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

# Run Monte carlo trials with pilot

RunMCSim(1)  
save(“./PilotData.jld”,“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)‘’’

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 11, 2018, 3:11am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/6 "2018-08-11T03:11:18Z")

</div>

Backticks (`, just to the left of the ‘1’ key on most keyboards) are different from single quotes ('). Please use backticks to quote your code as described in [this post](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) and check the result in the preview window.

---

<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, 4:10am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/7 "2018-08-11T04:10:06Z")

</div>

````nohighlight

include("MonteCarlo.jl")
include("Abstraction.jl")
include("PlotMCSim.jl")

# Run Monte carlo trials with pilot
RunMCSim(1)
save("./PilotData.jld","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.jld","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```
````

---

<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, 4:21am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/8 "2018-08-11T04:21:12Z")

</div>

Is it ok ?

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 11, 2018, 4:45am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/9 "2018-08-11T04:45:24Z")

</div>

No. You’re using backticks now, which is good, but not in the right way. See [this post (again)](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) for what it should look like and how to do it.

---

<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, 5:12am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/10 "2018-08-11T05:12:29Z")

</div>

I think, I finally understood. Can somebody help to fix the error in the code above. The error is:  
UndefVarErrror: save not defined

````julia
while loading /Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/Takeoff/Run.jl, in expression starting on line 10
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```
````

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 11, 2018, 6:03am UTC](https://discourse.julialang.org/t/error-in-method-definition-function-base-sub2ind-must-be-explicated-imported/13133/11 "2018-08-11T06:03:03Z")

</div>

Probably missing `using FileIO`? See [https://github.com/simonster/JLD2.jl/tree/v0.0.6#save-and-load-functions](https://github.com/simonster/JLD2.jl/tree/v0.0.6#save-and-load-functions).
