Importing MATLAB files

Nhập dữ liệu vào Python: Giới thiệu

Hugo Bowne-Anderson

Data Scientist at DataCamp

MATLAB

  • “Matrix Laboratory”
  • Industry standard in engineering and science
  • Data saved as .mat files

ch_2_4.005.png

Nhập dữ liệu vào Python: Giới thiệu

SciPy to the rescue!

  • scipy.io.loadmat() - read .mat files
  • scipy.io.savemat() - write .mat files
Nhập dữ liệu vào Python: Giới thiệu

What is a .mat file?

ch_2_4.010.png

Nhập dữ liệu vào Python: Giới thiệu

What is a .mat file?

ch_2_4.011.png

Nhập dữ liệu vào Python: Giới thiệu

Importing a .mat file

import scipy.io
filename = 'workspace.mat'
mat = scipy.io.loadmat(filename)

print(type(mat))
<class 'dict'>
  • keys = MATLAB variable names
  • values = objects assigned to variables
print(type(mat['x']))
<class 'numpy.ndarray'>
Nhập dữ liệu vào Python: Giới thiệu

Let's practice!

Nhập dữ liệu vào Python: Giới thiệu

Preparing Video For Download...