Export Matlab function as standalone python code which runs without Matlab Runtime

12 ビュー (過去 30 日間)
Francois
Francois 2023 年 11 月 8 日
コメント済み: Francois 2024 年 1 月 3 日
Hi,
I have a simple Matlab function without any args that generates a 1x100 vector and calculates the rms of that vector and writes it to a text file.
This function is also called in a sample test file to execute it.
I would like to be able to translate these .m files into Python standalone code; meaning I can run the Python code without any required software from Matlab like Matlab Runtime due to its large size.
I've tried the following:
  • Use the Library Compiler app from Matlab. This is good but requires Matlab Runtime on the system to be able to run (from what I've read)
  • Convert the Matlab code into standalone C/C++ code and use a Python wrapper (Cumbersome and might give compatibility problems in some cases)
So, my question: is there a way to translate these .m files into Python standalone code? If I could be able to use a UI like Library Compiler it would be even better.
  3 件のコメント
Francois
Francois 2023 年 11 月 13 日
Okay, thank you for your answer. I did find these resources which might help translate Matlab code to Python manually. Although the translation is not 100% correct and you might need to adapt some lines, it could speed the translation and has good flexibility nonetheless (you get just the code you want, compared to all the files and folders Matlab generates via Matlab Coder and Library compiler):
dpb
dpb 2023 年 11 月 14 日
No disagreement on the bulkiness of the MATLAB distribution model...there definitely should be a way for a targetted runtime for a specific app rather than the whole enchilada it currently is of virtually everything.

サインインしてコメントする。

採用された回答

Yash
Yash 2024 年 1 月 2 日
Hi Francois,
I understand that you are interested in exporting MATLAB function as standalone python code. Currently, MATLAB does not offer a direct UI-based tool that can automatically convert MATLAB code to Python code with a significant level of precision.
Altough you can use various tools like "MATLAB Engine API for Python", it's important to note that this still requires MATLAB to be installed, which you've indicated you want to avoid. For further information on MATLAB and Python interoperability tools, you may refer to the MATLAB Answer at this URL: https://www.mathworks.com/matlabcentral/answers/426258-how-to-convert-the-matlab-code-into-the-python#:~:text=Flag-,MATLAB%20provides,-two%2Dway%20integration
If you want a standalone Python code, you will have to manually rewrite the MATLAB functionality using Python.
Hope this helps

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by