3

It looks like savemat is producing .mat files that MATLAB cannot open when they contain Chinese characters, but loadmat is able to:

$ python -c 'from scipy.io import *; savemat("tmp.mat", {"test": "你好"}); print(loadmat("tmp.mat")["test"])' && matlab -nodesktop -r 'load tmp; exit'
['你好']

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

Error using load
Can't read file /home/tmp.mat.

Any ideas how I can either change savemat to output something MATLAB can open or change MATLAB settings such that I can read the files?

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Kathi
  • 99
  • 1
  • 5
  • Octave error: >> load tmp.mat warning: load: can not read multi-byte encoded UTF8 characters; replacing unreadable characters with '?' – hpaulj Aug 01 '18 at 01:22
  • yes got the same in Octave, but I dont see how I can fix it in matlab. Surely there must be a way to open .mat files with Chinese characters. – Kathi Aug 01 '18 at 01:27

1 Answers1

0

Based on the documentation of savemat and save I believe that savemat produces .mat files with an older format (what MATLAB calls -v6, that doesn't support Unicode (introduced in -v7).

You should be able to save .mat files of the newer format if you switch from savemat to an HDF5 writer like h5py or hd5storage. Alternatively, you can always store strings as byte arrays and interpret them later on.

See also: Creating a .mat file of v7.3 in python, Strings in HDF5.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99