Skip to content

Commit 2e3bfd9

Browse files
committed
Fixed string handling by checking the attribute of the dataset
1 parent 634ee88 commit 2e3bfd9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pymatbridge/matlab_magic.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ def loadmat(fname):
8080
data = {}
8181
for mem_name in f[var_name].iterkeys():
8282
if isinstance(f[var_name][mem_name], h5py.Dataset):
83+
# Check if the dataset is a string
84+
attr = h5py.AttributeManager(f[var_name][mem_name])
85+
if (attr.__getitem__('MATLAB_class') == 'char'):
86+
is_string = True
87+
else:
88+
is_string = False
89+
8390
data[mem_name] = f[var_name][mem_name].value
8491
data[mem_name] = np.squeeze(data[mem_name].T)
85-
# This is a quick hack. Need to find a better way
86-
# to identify string
87-
if data[mem_name].dtype == 'uint16':
92+
93+
if is_string:
8894
result = ''
8995
for asc in data[mem_name]:
9096
result += chr(asc)

0 commit comments

Comments
 (0)