This article was also published on the site: https://dzone.com/articles/write-matlab-functions-to-python.
Recently in my work I was re-writing algorithms developed in MatLab to Python, some functions are not so simple to adapt, especially the array functions that are called Cell Arrays.
MatLab has an API where you can call via Python the functions of the MatLab itself, but the idea was not to use MatLab, but the same algorithm works the same way using only Python and NumPy, the GNU Octace also has an API similar to that of MatLab.
To maintain compatibility I have created functions with the same name that are used in MatLab that is encapsulated in a class called Precision.
Make the repository clone and follow the instructions in the README file:
Below I will show some examples, these are contained in the unit tests.
Measuring the time spent in processing.
The output will look something like this:
Used to get a percentile. Example by creating a range of ordinal dates by cutting 5% from the left and 5% from the right.
The output will look something like this:
Convert cell array to ordinary array of the underlying data type.
The output will look something like this:
Convert array to cell array with consistently sized cells.
The output will look something like this:
Concatenate strings horizontally using strcat.
The output will look something like this:
Counts the number of values in x that are within each specified bin range. The input, binranges, determines the endpoints for each bin. The output, bincounts, contains the number of elements from x in each bin.
The output will look something like this:
Looking for unique values in array and returning the indexes, inverse, and counts.
The output will look something like this:
Looking for the overlays between two arrays returning the index.
The output will look something like this:
There are functions that are not exactly MatLab but will serve as support, I hope it can help someone. There is an interesting article in NumPy for users who are migrating from MayLab to Python.