Whether or not you are using Matlab you are still coding so why not use python, its Free! Python is an interpreter language that have high level abstractions to make coding easy, well, easier and if you coming from Matlab, most of the scripting skill you already have is translatable. This wiki space is dedicated to making Python coding easy with resources and link to resources that you will/may need to write awesome python programs.
Python and its modules
For coding in python like matlab you will need (the bare minimum):
- Python (of course), preferably Python 3.6 or above. Python 2.7 will no longer be supported by the developers.
- A text editor i.e. notepad++
To make things easier, the following software packages will help manage and develop your scripts/programs:
- Anaconda Distribution
Anaconda is an open-source distribution of python, that provides and manages the commonly used packages for data science and machine learning so you don't have to.
Currently (in 2019) we recommend python 3.6, because it is the most compatible version across different OS especially for Ubuntu 18.04 LT.
To install the latest python 3.6 using anaconda, download Anaconda3-5.2.0 from https://repo.anaconda.com/archive/.
Otherwise if compatibility is not important to you then the default Anaconda3 Distribution will do (https://www.anaconda.com/distribution/).
- Integrated development environment (IDE): pycharm IDE community addition (Recommended). This is to make your coding life easier.
Differences Between Matlab and Python
There are a lot of differences between Matlab and Python beside the fact that Python is free. The following is a list of differences you need to be aware of when switch from Matlab to Python.
- Python indexing starts at Zero
- Python uses square brackets [ ] instead of ( ) to for indexing arrays
- To perform matrix and array operation you need to import the numpy module in python
- There are other data structures in Python like dictionary
- You don't need to put a semi-colon at the end of your statement in Python
- In Python, white-space matters. Python use these white-spaces to define the scope of your code. Matlab use the "end" key word i.e. in the end of loops while Python does not.
Python have functions and methods. Functions are similar to Matlab functions, the way they work is the same, the way it is call is the the same but the way they are defined is a bit different.
Methods on the hand is also associated with an object:
To call a method you have to do this
To plot graphs in python use matplotlib
Useful tips and tricks
To find out what is your current working dir:
To find out what the real path of your relative path:
Setting Up Your Python Environment
The easiest way to setup Python is to install Anaconda and keeping the options as default. Once it is installed you can check the installing by either opening command prompt or anaconda prompt. Then in the window type: python or py and it should show the python scripting interface.
Next, install pycharm. Once installed it should look like this when you created a project:
It should automatically detect your python install. If not you can add it to your project by going into settings
Then to project: <name of your project> and Open Project Interpreter
Open drop down and click on show all ...
If the python interpreter is not shown, you can try adding it:
There is two options here, to simplify things we will just add an existing interpreter by first navigating to your python installation. Then press ok.
Then you are done and have python ready to go.
Recent space activity