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!