天天看點

python加載mat檔案,并轉換為txt格式

from scipy.io import loadmat
import numpy as np

def load_mat_data(filename):
    data = loadmat(filename)
    data_name = data.keys()
    a = list(data_name)
    data_name = a[-1]
    data = data[data_name]
    return data

import os
import dataio

path = 'D:\DataSets\Knee Point Cloud_seg\seg_data'
fileList = os.listdir(path) #讀取某個檔案夾下的全部檔案名字 ,存清單,

savepath ='D:\DataSets\Knee Point Cloud_seg\seg_data_txt'
for i,filename in enumerate(fileList):
    filepath = os.path.join(path,filename)
    data2 = load_mat_data(filepath)
    name = filename.split('.',1)
    np.savetxt(os.path.join(savepath,name[0]),data2)