We all know that matlab is a very good matrix calculation and analysis software, however, matlab comes with extremely jagged plotting effect, so, here to share a in python to read matlab processed data .mat file.
1. First of all, let's open up matlab here and type in two variables in the command line window at random.
matlab_x=1:0.01:10; matlab_y=sin(matlab_x);
2. After the calculation and processing, there will be two variable values in the workspace on the right side of matlab, namely matlab_y, matlab_x
3. Then, we place the mouse on the workspaceblank positionRight click and selectsave (a file etc) (computing), you can also use the shortcut ctrl + s to save when the workspace is in the work highlighting state, it will pop up to save the file name, here we save as
4. the next step is to use Python to read the data saved in the previous step in the matlab workspace Data. python we need to use the scipy library, here we first import it into the
import as scio
5. Read .mat file
data=('./')
6. View the current data data type
type(data)
The output is a dict dictionary type
7. Read the data that corresponds to what we want
Here we assume that we need to read the data matlab_y into python (here we use the numpy library to convert the data to an array type)
import numpy as np # Import matrix processing libraries python_y=(data['matlab_y']) # Assigning matlab data to python variables
to this article on the detailed python read matlab data (.mat file) article is introduced to this, more related python read matlab content please search for my previous posts or continue to browse the following related articles I hope you will support me in the future!