การนำเข้าไฟล์ MATLAB

Python เบื้องต้น: การนำเข้าข้อมูล

Hugo Bowne-Anderson

Data Scientist at DataCamp

MATLAB

  • "Matrix Laboratory"
  • มาตรฐานในวงการวิศวกรรมและวิทยาศาสตร์
  • บันทึกข้อมูลเป็นไฟล์ .mat

ch_2_4.005.png

Python เบื้องต้น: การนำเข้าข้อมูล

SciPy ช่วยได้!

  • scipy.io.loadmat() - อ่านไฟล์ .mat
  • scipy.io.savemat() - เขียนไฟล์ .mat
Python เบื้องต้น: การนำเข้าข้อมูล

ไฟล์ .mat คืออะไร?

ch_2_4.010.png

Python เบื้องต้น: การนำเข้าข้อมูล

ไฟล์ .mat คืออะไร?

ch_2_4.011.png

Python เบื้องต้น: การนำเข้าข้อมูล

การนำเข้าไฟล์ .mat

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

print(type(mat))
<class 'dict'>
  • keys = ชื่อตัวแปรใน MATLAB
  • values = อ็อบเจกต์ที่กำหนดให้ตัวแปร
print(type(mat['x']))
<class 'numpy.ndarray'>
Python เบื้องต้น: การนำเข้าข้อมูล

มาฝึกกันเถอะ!

Python เบื้องต้น: การนำเข้าข้อมูล

Preparing Video For Download...