mat2json, python读取mat成字典, 保存json

该博客介绍了如何使用Python程序将MATLAB的.mat文件转换为字典,并提供了可选功能将字典序列化为JSON文件。通过指定mat文件路径和json输出位置,可以实现数据的轻松转换。
摘要由CSDN通过智能技术生成

python程序, 实现matlab的.mat格式转化为dict / json .

  • 第一个参数mat_path代表需要转化的mat路径;
  • 第二个参数, 如果需要把字典序列化成json, 添加这一参数, 代表json存放位置;
  • 返回值: 转化好的字典
import os
import json
import scipy.io as spio
import pandas as pd

def loadmat(filename):
    '''
    this function should be called instead of direct spio.loadmat
    as it cures the problem of not properly recovering python dictionaries
    from mat files. It calls the function check keys to cure all entries
    which are still mat-objects
    '''
    data = spio.loadmat(filename, struct_as_record=False, squeeze_me=True)
    return _check_keys(data)

def _check_keys(dict):
    '''
    checks if entries in dictionary are mat-objects. If yes
    todict is called to change them to nested dictionaries
    '''
    for key in dict:
        if isinstance(d
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值