question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loadmat doesn't work on String arrays

See original GitHub issue

Describe the solution you’d like

I am trying to load a mat file with an array of strings in it. I have read the documentation and loadmat should work on v6 files, and v7-v7.2. I have tried saving the mat file from matlab as all of these formats and I have the same issue with each. The mat file loads with the numerical data, but not the string data. I’ve tried to search through the issues and I see that there are issues with implementing classdef’s in matlab as well as similar issues to mine come up with the file being loaded with a key ‘None’ the has a MatlabOpaque object.

Describe alternatives you’ve considered I’ve tried saving the string array as a separate array and this produces the same result. I have also tried all of the ideas in This stackoverflow question, and none of them allow me to load the strings. The h5py loads it in the same way.

At this point I cannot figure out how to load these strings in using any method.

from scipy.io import loadmat scipy.__version__

1.4.1

    mat_file = loadmat('data.mat',mat_dtype=True)
    mat_file

    {'__header__': b'MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Tue Apr  7       15:07:44 2020',
     '__version__': '1.0',
     '__globals__': [],
     'None': MatlabOpaque([(b'time', b'MCOS', b'string', array([[3707764736],
        [         2],
        [         1],
        [         1],
        [         3],
        [         1]], dtype=uint32))],
              dtype=[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')]),
     '__function_workspace__': array([[ 0,  1, 73, ...,  0,  0,  0]], dtype=uint8)}```

I have also tried setting all the relevant kwargs in the loadmat function with no different results.  

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ahyunSeocommented, Feb 9, 2021

Same here

2reactions
marcosauttocommented, Jan 17, 2021

Still facing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load a .mat file including string array to Python 3.6
@Rotem It worked! In MATLAB, I converted the strings to chars, then save under a .mat file then loaded in Python with scipy.io.loadmat....
Read more >
scipy.io.loadmat — SciPy v1.9.3 Manual
Name of the mat file (do not need .mat extension if appendmat==True). Can also pass open file-like ... Whether to convert char arrays...
Read more >
hdf5storage 0.1.14 documentation - PythonHosted.org
The first makes it so that enough metadata (HDF5 Attributes) are written that data can be read back accurately without it (or its...
Read more >
[SciPy-User] scipy.io.loadmat error when trying to read a .mat file
I'm using scipy 0.8.0 and having problems using the loadmat function. I've looked through the forum ... TypeError: buffer is too small for...
Read more >
Load a .mat file including string array to Python 3.6
I saved the two String arrays in a .mat file. I tried to load them in Python with this command: import hdf5storage Input...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found