0

I have a Matlab file containing a 750x1 double struct. All cells contain the number "18"

I load this file in Python, using:

loadmat(file_name, squeeze_me=True, struct_as_record=False)

To my surprise, all cells in the resulting numpy.ndarray contain the number "19" (dtype int)

I have tried to set mat_dtype=True, but the only difference is the resulting type. The import is still cells containing "19" instead of "18".

Anyone has a clue why this roundup/increment is happening?

  • I am not into matlab and python, but check this out: https://stackoverflow.com/questions/874461/read-mat-files-in-python there is an alternativ way to load the file – PV8 Sep 23 '19 at 11:21
  • sorry, this is unrelated to my problem. – R. Martins Sep 23 '19 at 11:36
  • did you try to load it with numpy or pandas? – PV8 Sep 23 '19 at 11:38
  • `scipy.io.loadmat` loads the mat file and converts the structs to numpy ndarray. – R. Martins Sep 23 '19 at 11:47
  • The mapping from a MATLAB `struct` to numpy array(s) can be confusing (layers of object dtype arrays, etc), but it shouldn't change the values of elements. But without a sample file, and/or some code we can't help. With MATLAB code I may be able to generate a .mat with `octave`, and try loading that. – hpaulj Sep 23 '19 at 16:40

1 Answers1

0

Nothing wrong with scipy or loadmat, turns out I was a moron who didn't notice that I was assigning a different struct to the variable (which turned out to be filled with 19s).

Problem embarrassingly solved...