Python读取Matlab mat 文件

Python读取Matlab mat的方法

MATLAB是一个编程平台,目前广泛用于数值计算、统计分析和生成算法。它是一种非常灵活的语言,允许我们将我们的工作与不同的编程语言如Python相结合。
MATLAB工作区将其所有变量和内容保存在一个mat文件中。在本教程中,我们将学习如何在Python中打开和读取mat文件。

文章目录

  • Python读取Matlab mat的方法
  • 使用`scipy.io` 模块去读取`.mat`文件


使用scipy.io 模块去读取.mat文件

若没有Scipy库需要进行手动安装:

PS D:\xxxx\xxxx> pip install scipy
Collecting scipy
  Downloading scipy-1.8.0-cp39-cp39-win_amd64.whl (36.9 MB)
     |████████████████████████████████| 36.9 MB 111 kB/s
Requirement already satisfied: numpy<1.25.0,>=1.17.3 in d:\anaconda3\envs\pytorch\lib\site-packages (from scipy) (1.21.5)
Installing collected packages: scipy
Successfully installed scipy-1.8.0

scipy.io模块有loadmat()函数,可以打开和读取mat文件。下面的代码显示了如何使用这个函数。

import scipy.io
mat = scipy.io.loadmat('file.mat') 

你可能感兴趣的:(基本语法,matlab,python,矩阵)