您的位置:首页 > 编程语言 > MATLAB

pickle file in matlab

2013-09-17 17:15 696 查看

Load pickle files in Matlab

Posted on June 12, 2013 by xcorr

http://xcorr.net/2013/06/12/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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: