Skip to content

Instantly share code, notes, and snippets.

@jason-s
Last active August 29, 2015 13:57
Show Gist options
  • Save jason-s/9632934 to your computer and use it in GitHub Desktop.
Save jason-s/9632934 to your computer and use it in GitHub Desktop.
samplestruct.mat
>>> import scipy.io
>>> S=scipy.io.loadmat('samplestruct.mat')
>>> S['foo']
array([[ ([[(array([[1, 2, 3]], dtype=uint8), array([[-1, -2, -3]], dtype=int16)
)]], [[123]])]],
dtype=[('bar', 'O'), ('quux', 'O')])
>>> S['foo']['bar']
array([[ array([[([[1, 2, 3]], [[-1, -2, -3]])]],
dtype=[('tweedledee', 'O'), ('tweedledum', 'O')])]], dtype=object)
>>> S['foo']['bar']['tweedledee']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: field named tweedledee not found.
S = struct('foo',struct('bar',struct('tweedledee',[1,2,3],'tweedledum',[-1,-2,-3]),'quux',123));
save('samplestruct.mat','-struct','S');
with open('samplestruct.mat','w') as f:
f.write("MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Tue Mar 18 13:19:09 2014 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x01IM\x0f\x00\x00\x00\x80\x00\x00\x00x\x9c\xe3c``\x08`d``\x03\xd2\x1c@\xcc\xc4\x00\x01\xacP>#\x1c33\xa4\xe5\xe7\x03\xc5Y\xc0r 1. NJ,b`(,-\xad\x80\xea\xe3\x03\xe2\x13\x0c\xc4\x98\x07\x13ga\xe0\x86\xf2\xc5\x80\xb8\xa4<55%'5%5\x15\xce,\xcd\x85\x9ak\x80d.\x1b\x16s\x99\x91\xcce\x02\xf2\x18\x99\x98\xc1\xfa,H\xd0\xc7\x0cU\xf3\xff\xff\xbf\xff\x7f\xff\x13g/\xb2\x7f\x98\x80\xacj \r\x00\xc2\x02\x16\x0c")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment