Converting from Matlab to Python?
7 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Shiva Kalyan Diwakaruni
on 3 May 2021
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
0 Comments
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!