Matlab Code to Python Code

14 次查看(过去 30 天)
RA RA
RA RA 2023-1-2
Objective - Convert Matlab code into Python code so that one can run it without licence on python and web
Key Factors
  • Matlab reads csv/excel files that dynamically change on daily/weekly/intraday basis . These files are generated externally either from python or other sources and then are used in Matlab
  • Matlab code uses Matlab toolboxes and specific matlab functions like model, pdf generation etc. Not sure how Python equivant code of these toolbox specific functions (model) can be generated ?
Tried numerious sources to get it running independently in Python but could not get the final solution till date. A lot of psedo solutions came in but not a solution. Perhaps an expert can only address this. Thanks for the help!
  2 个评论
Walter Roberson
Walter Roberson 2023-1-2
model? As in Model Predictive Control? Or as in an expression with parameters to be fit using Curve Fitting Toolbox or nonlinear fitting?
RA RA
RA RA 2023-1-3
By "model" function, what was meant was any function within a toolbox. It could a specific "model" in a toolbox say IRIS or any other functions like reporting, statistics etc. in any toolbox. Could be something in deep learning toolbox as so on. So while converting the Matlab code (that uses Matlab speciic toolbox too) in to Python, also need to convert the toolbox specific functions into Python, so that things can run independently in Python for that specific Matlab App. Thanks!

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2023-1-3
You are asking for a tool that will convert arbitrary MATLAB code to Python code, including toolboxes that Mathworks implemented using compiled code.
No such tool exists. It is unlikely that such a tool will ever exist.
What does exist is MATLAB Compiler SDK, layered on top of MATLAB Compiler. It is able to create executable libraries that can be called from Python. It does not create Python code: it is the MATLAB internal execution engine made available in DLL form. Some toolboxes cannot be deployed this way, such as the Symbolic Toolbox.
  3 个评论
David Willingham
David Willingham 2023-1-4
I'd recommend creating a microservice. A video showing how to do this can be found here:
Walter Roberson
Walter Roberson 2023-1-4
So, total replication from matlab to python is not possible, specially when there are matlab specific toolboxes used in the matlab app ?
Only through a detailed manual rewrite. There might potentially be tools to convert MATLAB syntax to Python, but such a tool would not be able to convert the internal non-MATLAB code.
Are there real life use share of deploying advanced matlab apps in Python and on web using Matlab Compiler SDK?
Sorry, not something I have ever been involved in. Some people have mentioned having done such things, but generating compiled executables is not something that I have ever been involved with.
Do we need Matlab licence to run these executable libraries in Python ?
No
Can the backend dynamic excel/csv data files that are part of the executable libraries, be changed on daily/intraday basics ? If yes, how ?
When you compile files into the executable, then they get packaged into the archive. The first time the executable is run, it unpacks the archive into a directory hierarchy, uncluding unpacking the included non-source files into unencrypted files. If something has write access to the expanded directory, the data files could be written into. There is no built-in facility to automatically update files from some central site -- you would need to program updates into the executable.
User feeds different values for the parameters from the web/front end. Will the executable libraries ingest new parameter values dynamically and provide results using these new input values? If yes, how ?
The executable can locally store and retrieve any values it needs to give the illusion of continuity. If multiple instances of the server are running, you would need to program in access conflict resolution of some sort.
The two synchronization mechanisms that are built-in to MATLAB are:
There is, however, no built-in user-accessible facility for semaphores or similar.
Or you might want to use something like MATLAB Production Server https://www.mathworks.com/products/matlab-production-server.html
How can we know whether a specific toolbox cannot be used with the matlab compiler SDK solution ? Is there a list or a way to assess ?
https://www.mathworks.com/products/compiler/compiler_support.html lists by toolbox. https://www.mathworks.com/help/compiler/unsupported-functions.html lists the core MATLAB language commands that cannot be compiled (for example, debugger commands.)
Finally, is there a place to get a matlab expert who can test and deploy this solution
Note: I am an outside volunteer who attempts to answer questions based upon personal experience and reading documentation and (trying to) remember information that other people have posted. I have not happened to have a need for deployment myself.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Python Package Integration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by