gpt4 book ai didi

python - MATLAB打开带有savemat写的汉字的.mat文件时报错

转载 作者:行者123 更新时间:2023-11-28 19:02:09 25 4
gpt4 key购买 nike

看起来 savemat 正在生成 MATLAB 在包含中文字符时无法打开的 .mat 文件,但 loadmat 能够:

$ 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.

关于如何更改 savemat 以输出 MATLAB 可以打开的内容或更改 MATLAB 设置以便我可以读取文件的任何想法?

最佳答案

基于 savemat 的文档和 save我相信 savemat 会生成旧格式的 .mat 文件(MATLAB 称之为 -v6,它不支持 Unicode(在 -v7).

如果您savemat 切换到HDF5 writer,您应该能够保存较新格式的.mat 文件,例如h5pyhd5storage .或者,您始终可以将字符串存储为字节数组并在以后解释它们。

另请参阅:Creating a .mat file of v7.3 in python , Strings in HDF5 .

关于python - MATLAB打开带有savemat写的汉字的.mat文件时报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51624061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com