# Accessing Matlab-function from Julia

**URL:** <https://discourse.julialang.org/t/accessing-matlab-function-from-julia/54221>\
**Category:** New to Julia\
**Tags:** matlab\
**Created:** [January 29, 2021, 8:01pm UTC](https://discourse.julialang.org/t/accessing-matlab-function-from-julia/54221 "2021-01-29T20:01:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andre96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andre96/32/21530_2.png) [@andre96](https://discourse.julialang.org/u/andre96)\
**Post date:** [January 29, 2021, 8:01pm UTC](https://discourse.julialang.org/t/accessing-matlab-function-from-julia/54221/1 "2021-01-29T20:01:40Z")

</div>

Hello everyone,

I recently started to work with Julia and need to evaluate some custom matlab-functions in my julia-scripts. Therefore, I added the package MATLAB.jl and updated the environment variable MATLAB\_HOME to the installation directory of the matlab version I use. However, I am not able to execute any of the mentioned examples in [https://github.com/JuliaInterop/MATLAB.jl](https://github.com/JuliaInterop/MATLAB.jl) .

For example, if i want to execute

```julia
using MATLAB

x = 5
mat"plot($x, sin($x))"

```

I get the following error-message

```julia
LoadError: UndefRefError: access to undefined reference

in expression starting at D:\UNI\Julia\test_matlab.jl:4

MSession(::Int64; flags::String) at engine.jl:26

MSession at engine.jl:23 [inlined]

MSession at engine.jl:23 [inlined]

get_default_msession at engine.jl:88 [inlined]

put_variable(::Symbol, ::Int64) at engine.jl:159

top-level scope at matstr.jl:160

include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088

```

Moreover, I do not get this error for this example only, but for every listed example under [GitHub - JuliaInterop/MATLAB.jl: Calling MATLAB in Julia through MATLAB Engine](https://github.com/JuliaInterop/MATLAB.jl#use-matlab-engine) .

Any suggestions what could cause this error-message?

Best,  
andre

---

<div class="post-metadata">

**Author:** ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)\
**Post date:** [January 29, 2021, 9:29pm UTC](https://discourse.julialang.org/t/accessing-matlab-function-from-julia/54221/2 "2021-01-29T21:29:37Z")

</div>

I can not recreate your error. I got this:

```julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.4.2 (2020-05-23)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using MATLAB

julia> x = 5
5

julia> mat"plot($x, sin($x))"
Undefined function 'sin' for input arguments of type 'int64'.

```

And I was able to get a MSession, it seems like you couldn’t.

```julia
julia> MATLAB.get_default_msession()
MSession(Ptr{Nothing} @0x0000000032efd420, UInt8[0x00, 0x6e, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x20 … 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], Ptr{UInt8} @0x0000000033ac5f40)

```

I am on Windows 10, Julia 1.4.2, MATLAB.jl v0.7.3, MATLAB R2017b. And I didn’t set `MATLAB\_HOME’.
