Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SMOP to convert Matlab into Python code

I've installed SMOP via pip and it seemed to work fine. I have smop-script.py and smop.exe files in my python folder \scripts\ folder.

Let's say I have a matlab file called myMatlabFile.m located in C:\Users\MyMatlabCode. How do I use smop to translate that file?

The SMOP documentation only includes an example of opening a file contained in a \smop\ folder with a main.py and I don't have anything like that. Also, the github page doesn't say whether it works only with 2.7 or 3. or whatever.

I was hoping that this package would speed up my Matlab -> Python 3.6 conversion, but if there are better translators out there now please let me know that too/instead.

like image 989
Aaron Bramson Avatar asked Apr 19 '18 10:04

Aaron Bramson


People also ask

How do I convert MATLAB code to Python code?

To convert Matlab to python, a tool named SMOP (Small Matlab and Octave to Python Compiler) is used. This tool is capable of understanding basic Matlab code and then parsing it to python. Although there are always limitations to every tool, this tool works best for small-level codes.

What is SMOP in Python?

Summary. SMOP stands for Small Matlab/Octave to Python compiler. It is supposed to help those who attempt migration from Matlab to Python. Despite the similarities between the two languages, there are enough differences to make manual translation too time consuming.

Does MATLAB code work in Python?

MATLAB provides flexible, two-way integration with many programming languages, including Python. This allows different teams to work together and use MATLAB algorithms within production software and IT systems.


1 Answers

I just tried using to convert a matlab file with SMOP and it worked. I installed the software using pip in Anaconda Prompt environment.

pip install smop

After the installation I had the 0.41 Version.

I copied the file that I wanted to convert in the folder where I ran the pip code in the Anaconda Prompt environment.

Then I used the code smop and the file name .m and got a file .py in the same folder.

smop VI.m
like image 188
Carlos Melo Avatar answered Sep 17 '22 17:09

Carlos Melo