# Embed Matlab function files in Julia

**URL:** <https://discourse.julialang.org/t/embed-matlab-function-files-in-julia/34312>\
**Category:** New to Julia\
**Tags:** matlab\
**Created:** [February 7, 2020, 5:02pm UTC](https://discourse.julialang.org/t/embed-matlab-function-files-in-julia/34312 "2020-02-07T17:02:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![uwechsler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uwechsler/32/5223_2.png) [@uwechsler](https://discourse.julialang.org/u/uwechsler)\
**Post date:** [February 7, 2020, 5:02pm UTC](https://discourse.julialang.org/t/embed-matlab-function-files-in-julia/34312/1 "2020-02-07T17:02:36Z")

</div>

I would like to call some custom `Matlab` functions in julia which are defined in separate `.m` file.

As MVP, consider the file `Cps.m` which contains the following code

```matlab
function C = Cps(T)
% solid maltodextrin
% from Jakob Slots master thesis pp. 87
C = (1548.8+1.9625.*(T-273.15)-5.9399e-3*(T-273.15).^2)*1e-3;%1000;%0*2e3 + 4e3*0;
end

```

Is there a way to import these functions into julia with `Matlab.jl` such that I can call the matlab function  
as

```julia
mat"""
    $res = Cps($input)
"""

```

or in a similar way?

---

<div class="post-metadata">

**Author:** ![Balinus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balinus/32/243_2.png) [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Post date:** [February 7, 2020, 8:02pm UTC](https://discourse.julialang.org/t/embed-matlab-function-files-in-julia/34312/2 "2020-02-07T20:02:40Z")

</div>

Never tried to interop with MATLAB, but I’m pretty sure you can find some example here: [https://github.com/JuliaInterop/MATLAB.jl](https://github.com/JuliaInterop/MATLAB.jl)

Hope this help!

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 7, 2020, 8:30pm UTC](https://discourse.julialang.org/t/embed-matlab-function-files-in-julia/34312/3 "2020-02-07T20:30:11Z")

</div>

I have also never tried this but my guess is that as long as the Cps.m file is on Matlab’s path then you should be able to do exactly what said. The docs say that

```julia
mat"""

"""

```

just executes arbitrary Matlab code. I would take that to mean if you typed it into the Matlab command window it would work.

---

<div class="post-metadata">

**Author:** ![uwechsler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uwechsler/32/5223_2.png) [@uwechsler](https://discourse.julialang.org/u/uwechsler)\
**Post date:** [February 8, 2020, 1:13pm UTC](https://discourse.julialang.org/t/embed-matlab-function-files-in-julia/34312/4 "2020-02-08T13:13:27Z")

</div>

Thanks, I did not consider that the functions are already accessible if the path to the folder containing the function is already in the search path, so I can do the following.

```julia
mat"""
addpath($functionpath)
Cps(1.3)
"""

```
