matlab

python equivalent for MATLABS vratiotest

python equivalent for MATLABS vratiotest Question: I am following the book Algorithmic Trading and I am on Chapter 2: The Basics of Mean Reversion. I have a few pairs and their close prices and I want to check the spread of which pair is mean-reverting. The book uses MATLAB for all its programming and I …

Total answers: 1

Multiply tensors containing matrices, following matrix multiplication rule

Multiply tensors containing matrices, following matrix multiplication rule Question: Say I have a tensor, where A, B, C, and D are all 2×2 matrices: M = [[A, B], [C, D]] How do I get to the power of n, for example with n=2, with Python or MATLAB M^2 = [[A@A + B@C, A@B + B@D], …

Total answers: 3

How do I create a Data Variable in an xarray.DataArray?

How do I create a Data Variable in an xarray.DataArray? Question: How do I assign data to or create a ‘Data Variable’ in a xarray.DataArray or finally in the nc-file when saving the DataArray? When creating the xarray.DataArray, it simply stores the data as an array but not as a ‘Data Variable’ as one is …

Total answers: 2

Simulation of Markov chain slower than in Matlab

Simulation of Markov chain slower than in Matlab Question: I run the same test code in Python+Numpy and in Matlab and see that the Matlab code is faster by an order of magnitude. I want to know what is the bottleneck of the Python code and how to speed it up. I run the following …

Total answers: 1

Emulating Matlab Mesh Plot in Matplotlib yielding shadow effects

Emulating Matlab Mesh Plot in Matplotlib yielding shadow effects Question: I have this meshplot that looks very clean in matlab for a 3d surface (Ignore the red border line): And I am trying to emulate the same image in matplotlib. However, I get this weird shadow effect where the top of the surface is pure …

Total answers: 2

Change properties of rose plot

Change properties of rose plot Question: I use the function rose2 in my script in order to plot a rose plot. I am working with Matlab 2016a and thus still use the rose function. I use rose2 in order to be able to set the maximum value for the r axis and fill the triangles. …

Total answers: 2

How to transfer variables from Matlab to Python

How to transfer variables from Matlab to Python Question: I would like to transfer some of variables calculated in Matlab (R2022a) to Python environment (3.10). I have figured out that the SciPy package has function loadmat() and I may save vars in mat file and then I should read the file with Python. However, I’m …

Total answers: 2

Converting Matlab function to Python

Converting Matlab function to Python Question: I have a Matlab file that I’m looking to convert into Python. Part of it is functions and I’m a bit confused by it. In the Matlab code, there is a function that looks like this: function [u, v, speed, dir] = NewCalculations(data) Would the Python equivalent of this …

Total answers: 1