Skip to content

Instantly share code, notes, and snippets.

@sjqtentacles
Created September 13, 2015 23:32
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sjqtentacles/bc2f69b0c4430211bcad to your computer and use it in GitHub Desktop.
Save sjqtentacles/bc2f69b0c4430211bcad to your computer and use it in GitHub Desktop.
Converting .mat to .csv using python
import scipy.io
import numpy as np
data = scipy.io.loadmat("subject.mat")
for i in data:
if '__' not in i and 'readme' not in i:
np.savetxt(("filesforyou/"+i+".csv"),data[i],delimiter=',')
@GEMSS3D
Copy link

GEMSS3D commented Sep 23, 2016

Do we need additional python code other scipy and numpy?

@ah89
Copy link

ah89 commented Sep 21, 2017

It works

@yangxu698
Copy link

if it shows 'Mismatch between array dtype ('object') and format specifier' in Python
change the last line:
np.savetxt(("filesforyou/"+i+".csv"),data[i],fmt='%s',delimiter=',')

@ritzzel
Copy link

ritzzel commented Jan 10, 2019

I am getting following error.
ParserError: Error tokenizing data. C error: Expected 14 fields in line 1117, saw 15

@ssp2195
Copy link

ssp2195 commented Jun 23, 2019

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

@mounareddy2023
Copy link

TypeError: Mismatch between array dtype ('[('cycle', 'O')]') and format specifier ('%.18e')

@sjqtentacles
Copy link
Author

yeah this code worked on my macbook 4 years ago, idk if it still does ...

wow I was a shitty programmer back then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment