pickle file in matlab

本文介绍了一种在Matlab中加载Python pickle文件的方法。通过调用Matlab系统命令并设置环境变量LD_LIBRARY_PATH,使用Python脚本将pickle文件转换为Matlab可读的.mat文件格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Load pickle files in Matlab

It’s easy enough to load .mat files in Python via the scipy.io.loadmat function. But what about loading .pickle files into Matlab? That’s easy enough by calling a system command in Matlab, like so:

function [a] = loadpickle(filename)
    if ~exist(filename,'file')
        error('%s is not a file',filename);
    end
    outname = [tempname() '.mat'];
    pyscript = ['import cPickle as pickle;import sys;import scipy.io;file=open("' filename '","r");dat=pickle.load(file);file.close();scipy.io.savemat("' outname '",dat)'];
    system(['LD_LIBRARY_PATH=/opt/intel/composer_xe_2013/mkl/lib/intel64:/opt/intel/composer_xe_2013/lib/intel64;python -c ''' pyscript '''']);
    a = load(outname);
end

Note that I’m setting the LD_LIBRARY_PATH environment variable since Matlab seems to reset this variable internally and it causes .so module import errors in Python.

转载于:https://www.cnblogs.com/huashiyiqike/p/3326670.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值