Skip to content
Advertisement

Tag: matlab

Convert phase angle equation from Matlab to Python

I’m trying to adapt code from Matlab to Python. Specifically measuring the phase angle from a group of angles. So using the df below, I have 5 individual labels with an associated angle. I want to measure the phase angle between these points. In Matlab the angle for each Label is passed to the following: This equals the following: I

Is there a MatLab equivalent of Python matplotlib’s tight_layout()?

I find the amount of whitespace around plots in both normal Python Matplotlib and Matlab quite annoying, specifically the left and right margins that make your plot look tiny when inserting the saved (landscape) figure into a standard (portrait) .doc or .pdf file. Fortunately Python Matplotlib has the “tight_layout()” functionality that takes care of this beautifully. Does Matlab have a

Length function in Matlab to python

I am attempting to translate the following Matlab code into python d=real(ifft(fft(fw).*conj(fft(rv)))) d=[d(ld+1:length(d)) d(1:ld)]’ but the problem occurs in the following line of code: ld=length(d) My question is about the length function in matlab. How do I translate this correctly to python, to get an integer? I have tried np.size(d,1) and np.prod(d.shape). But both of these return a ‘list’ and

Extract N number of patches from an image

I have an image of dimension 155 x 240. Like the following: I want to extract certain shape of patchs (25 x 25). I don’t want to patch from the whole image. I want to extract N number of patch from non-zero (not background) area of the image. How can I do that? Any idea or suggestion or implementation will

How to save Python 1D, 2D or 3D NumpPy array into MATLAB .mat

Python’s SciPy package has a function that saves Python variable into MATLAB’s .mat file https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.savemat.html However, the documentation lacks examples, and I don’t know what is the dictionary of variables it wants as an input. Say I have a 2D NumPy array A and a 3D NumPy array B, how do I save them into a .mat file called my_arrays.mat?

Matlab equivalent to Python’s figsize

In Python’s matplotlib.pyplot the figsize command allows you to determine the figure size, eg. Is there an equivalent command in Matlab that does this? These old posts show different solutions but none are as clean as Python’s figsize. Answer Since you aim for saving/exporting your figure, you must pay attention to the right Figure Properties, namely: PaperPosition, PaperSize, and PaperUnits.

Loading Matlab files into Python

I am attempting to understand the difference between loading a data file into Python and into Matlab in order to translate some code. I have a line of code that goes: When I run the code in Matlab I know that the data is in workspace. There is a 224×501 double called datalib and a 501×29 double called names. The

implement mat2gray in Opencv with Python

I have the same problem with him: Scaling a matrix in OpenCV I got the same problem with him, I have a colored picture, I used matlab to read the picture: Input = imread(‘input1.jpg’);, and the format of the picture is 612x612x3 uint8, I print the 5x5x1 pixel in the picture as below:Input(1:5,1:5,1) by using the mat2gray function: rgb_out =

Advertisement