# Calling julia code from matlab

**URL:** <https://discourse.julialang.org/t/calling-julia-code-from-matlab/58598>\
**Category:** General Usage\
**Tags:** question, package, embedding, matlab, build\
**Created:** [April 5, 2021, 8:34am UTC](https://discourse.julialang.org/t/calling-julia-code-from-matlab/58598 "2021-04-05T08:34:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noodle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noodle/32/22901_2.png) [@Noodle](https://discourse.julialang.org/u/Noodle)\
**Post date:** [April 5, 2021, 8:34am UTC](https://discourse.julialang.org/t/calling-julia-code-from-matlab/58598/1 "2021-04-05T08:34:04Z")

</div>

Hello everyone

I am trying to call Julia codes from MATLAB, as I need to send my Julia code to a MATLAB user.

It seems for Julia \>1.0 the solution is [GitHub - byuflowlab/Mex.jl: Embedding Julia in the MATLAB process.](https://github.com/byuflowlab/Mex.jl)

I followed the readme file: first installed MATLAB.jl from Julia and then added this Mex package in Julia by

]add [GitHub - byuflowlab/Mex.jl: Embedding Julia in the MATLAB process.](https://github.com/byuflowlab/Mex.jl)

the readme file says this build process will build the mexjulia MEX function from the source.

But when I try jl.eval(‘2+2’) in MATLAB, it shows:

_It appears the mexjulia MEX function is missing. Consider building “Mex.jl”.\n_

Just to make sure MATLAB.jl is properly installed, I could do  
using MATLAB  
using Mex

in Julia and I am able to call mat”2+2” from Julia and get 4.0 as an output.

So it seems the mexjulia MEX function is not properly installed?

I have been following the steps and am quite confused about what I missed. I also looked through previous posts on this topic but still couldn’t figure it out.

Does anyone have some ideas about what did I miss?

Thank you very much!!

---

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [April 13, 2021, 1:33pm UTC](https://discourse.julialang.org/t/calling-julia-code-from-matlab/58598/2 "2021-04-13T13:33:37Z")

</div>

I’m having this same issue. It looks like [this fork](https://github.com/jebej/Mex.jl) is the most actively maintained of the Mexes, so I opened up [an issue there](https://github.com/jebej/Mex.jl/issues/7).

---

<div class="post-metadata">

**Author:** ![Noodle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noodle/32/22901_2.png) [@Noodle](https://discourse.julialang.org/u/Noodle)\
**Post date:** [April 20, 2021, 5:26am UTC](https://discourse.julialang.org/t/calling-julia-code-from-matlab/58598/3 "2021-04-20T05:26:55Z")

</div>

Update: later I figured this was a directory issue with the Build process, the file can not locate proper location.

But even after I correct that error, the mex function call usually crashes. So I instead use Matlab call python call Julia.

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [July 18, 2021, 6:42am UTC](https://discourse.julialang.org/t/calling-julia-code-from-matlab/58598/4 "2021-07-18T06:42:36Z")

</div>

Hi @Noodle, could you give a small complete example how to go the Matlab/Python/Julia route?

The search on this topic is frustrating, the development appears to have ended in 2018.  
But calling Julia from Matlab should still be a hot topic, or as other posters said:

**Calling Julia from Matlab, replacing mex, would be the smoothest path to sneak Julia into a company.**
