matlab日期字符串在python scipy.io中导致java lang字符串 [英] matlab date string results in java lang string in python scipy.io

查看:93
本文介绍了matlab日期字符串在python scipy.io中导致java lang字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我在Matlab中有一个<1x1 java.lang.String>类型的字段. 其值为 13:06:40

  • I have a field of type <1x1 java.lang.String> in Matlab. Its value is 13:06:40

当我在python中读取该mat文件时,它会转换为

When I read this mat-file in python, It gets converted to

MatlabOpaque([ ('', 'java', 'java.lang.String', [[172, 237, 0, 5, 116, 0, 8, 49, 50, 58, 48, 49, 58, 53, 49]])], 
      dtype=[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')])

  • 我使用scipy.io将其保存回MAT文件,并且我具有上面dtype而不是<1x1 java.lang.String>
  • 的结构

    • I save this back to MAT-file using scipy.io and I have a struct with the dtype above instead of <1x1 java.lang.String>
    • 我可以使用python 检索时间戳并将其另存为java.lang.String对象吗?

      Any way I can retrieve the time stamp using python and save it as a java.lang.String object ?

      推荐答案

      使用python中的matlab类访问.mat文件

      关于具有类似loadmat显示的MATLAB类对象的询问:

      asks about a MATLAB class object with a similar loadmat display:

      MatlabOpaque([ (b'futureDS', b'MCOS', b'cStream', [[3707764736], ...])], 
        dtype=[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')])
      

      Python中没有什么可以解码这种MATLAB或Java对象.如果您需要在MATLAB和scipy之间来回发送数据,请使用基本的MATLAB数组,单元格和结构.

      There's nothing in Python that can decode this kind of MATLAB or Java object. If you need to send data back and forth between MATLAB and scipy stick with the basic MATLAB arrays, cells, and struct.

      您可以尝试解析该arr数字列表.由于它们均<256,因此它们可能表示字节.您不能将其转换为普通的MATLAB字符串吗?

      You could try to parse that arr list of numbers. Since they are all <256, they probably represent bytes. Can't you convert it to an ordinary MATLAB character string?

      In [117]: x=[172, 237, 0, 5, 116, 0, 8, 49, 50, 58, 48, 49, 58, 53, 49]
      In [118]: np.array(x,np.uint8).tostring()
      Out[118]: b'\xac\xed\x00\x05t\x00\x0812:01:51'
      

      最后8个字符看起来像一个时间戳.但是您对java.lang.String对象了解什么吗?

      The last 8 characters look like a time stamp. But do you know anything about java.lang.String objects?

      这篇关于matlab日期字符串在python scipy.io中导致java lang字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆