# Call a PowerModels' function in Matlab

**URL:** <https://discourse.julialang.org/t/call-a-powermodels-function-in-matlab/45647>\
**Category:** Optimization (Mathematical)\
**Created:** [August 27, 2020, 9:41pm UTC](https://discourse.julialang.org/t/call-a-powermodels-function-in-matlab/45647 "2020-08-27T21:41:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)\
**Post date:** [August 27, 2020, 9:41pm UTC](https://discourse.julialang.org/t/call-a-powermodels-function-in-matlab/45647/1 "2020-08-27T21:41:19Z")

</div>

Hi All,

I want to call the bound tightening code in the PowerModels (i.e. following function) in Matlab.

```julia
run_obbt_opf(case, upper_bound, solver, model_constructor= QCWRTriPowerModel)

```

I tried to call “bound\_tightening\_call\_from\_matlab” script in which it calls and runs the “run\_obbt\_opf” function by the following command. For whatever reason the following code doesn’t recognize the test case. I use Julia v.06. Can you please let me know how I can fix this?

```julia
jl_command = ['julia -e "include("""C:\\Users\\Rasoul\\.julia\\v0.6\\bound_tightening_call_from_matlab.jl"""); run_obbt_opf(casename,' num2str(upper_bound) ',' solver ',' model ')"'];
[cmdstatus,out] = system(jl_command);

```

My second question is about saving the output of the bound tightening code. Is there any function that can save the output for the bound tightening code as test\_case.m? Thanks in advance!

All the best,  
Rasoul

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [August 28, 2020, 3:42pm UTC](https://discourse.julialang.org/t/call-a-powermodels-function-in-matlab/45647/2 "2020-08-28T15:42:41Z")

</div>

I don’t know Matlab that well, so I can’t speak to how one would call Julia. I can recommend this workflow to export the bound information as a Matpower data file, which may serve your needs,

```julia
using Ipopt; using PowerModels

solver = optimizer_with_attributes(Ipopt.Optimizer, "tol"=>1e-6, "print_level"=>0)

case, stats = run_obbt_opf!("pglib_opf_case5_pjm.m", solver)

open("pglib_opf_case5_pjm-bt.m", "w") do io
    export_matpower(io, case)
end

```

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [August 28, 2020, 4:37pm UTC](https://discourse.julialang.org/t/call-a-powermodels-function-in-matlab/45647/3 "2020-08-28T16:37:11Z")

</div>

> [@Rasoul](#):
>
> I use Julia v.06

Why? Is it because of [GitHub - MatlabCompat/MatlabCompat.jl: Source of MatlabCompat.jl](https://github.com/MatlabCompat/MatlabCompat.jl) ?

There’s [GitHub - JuliaInterop/MATLAB.jl: Calling MATLAB in Julia through MATLAB Engine](https://github.com/JuliaInterop/MATLAB.jl) to call, and I’ve also been calling (through Oct2Py in Python) to Octave, MATLAB clone, but it may bot have the functions you want, e.g. toolboxes.

I don’t know about your case, I’ve been translating MATLAB code myself to Julia, and there are some similar packages that actually work in Julia 1.0, to help with compatibility maybe with some overlap with the one above, that probably someone should update. There’s also a Matlab-to-Julia syntax “transpiler”/compiler, it can be helpful, just note it’s not perfect, and may mistranslate, introduce bugs, extra ’ that is transpose, is the only major issue…
