Converting from Matlab to Python?

7 次查看(过去 30 天)
I have a code in matlab and I need to convert it to python but I do not have any idea how to do it. ANY help would be MUCH appreciated.
I have no idea when to use numpy and append and other functions that don't necessarily need to be specified in matlab.
As of right now, I have only switched "%" to "#" and "disp" to "print"
I have also changed the [start:increment:end] matrices to: range(start,end,increment)

回答(1 个)

Shiva Kalyan Diwakaruni
Hi,
1) P_og declaration in line 9 can remain the same as list declaration is same in python too
2) You can replace length() with len()
3) Syntax of if and else is little different in python, you can checkout the below resource for that
4) you need to use pow() function in python instead of '^'
5) list accessing in python is done using [] instead of () so you need to replace T(..) to T[] and remember that in matlab indexing starts from 1 unlike python whose list indexing starts from 0
6) You can follow the below cheatsheet to find matlab equivalent functions of python and replace them all
7) You can check out the below resources for sort function in python
Hope it helps,
Thanks

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by