How can libraries of functions compiled with Matlab Complier SDK be accessed in Python?
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to evaluate the Matlab Compiler SDKs functionality to port a large code base in Matlab to be used in Python. I have a folder of matlab .m functions that all of the form:
function [y1, y2,...] = funcname(x1, x2, ...)
Matlab code and comments
y1 = f(x1,x2,...);
y2 = f(x1,x2,...);
end
The individual function scripts have varying numbers of input and output arguments but all call common Matlab functions or other functions in the source folder. So I have a list of files
- function1.m
- function2.m
- functionN.m
I have compiled them using the functions into a python package using the Matlab Compiler and run the installation using the GUI and Python setup files produced in the for_redistribution_files_only folder using Anaconda.
The library shows up in ~\Anaconda\Lib\site-packages\ repository. How do I load this into Python and call the functions included in the complied package? Ideally, I would like to create a class structure in Python that is populated by the individual function names used to create the library.
The Mathworks documentation only shows how to handle a single file http://www.mathworks.com/help/compiler_sdk/gs/create-a-python-application-with-matlab-code.html.
Thanks in advance.
0 件のコメント
採用された回答
Alan Frankel
2016 年 3 月 15 日
Once you have obtained a package handle via the initialize command, you can use it to call any function within the package. The example in the documentation happens to call a function that has the same name as the package, but this does not need to be the case. Let's say your package is called pkg and contains functions function1, function2, and function3. Then you could execute:
import pkg
pk = pkg.initialize()
pk.function1(arg1, arg2)
pk.function2()
ret = pk.function3(arg1)
...
pk.terminate()
The package has a flat structure; all functions it contains are at the same level.
I assume that ~\Anaconda\Lib\site-packages\ is in your Python path. If not, you will need to manipulate your Python path to include it.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Compiler SDK についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!