How can i open dataset in matlab which is .pkl format?

109 次查看(过去 30 天)
I get a dataset in pickle format From a Author,but i want to do my project in matlab. so which command in matlab which help to open and use that datast.

回答(2 个)

Tim R
Tim R 2020-1-20
Here's a quick solution based on the links assuming you've set-up Matlab to point to the right Python ver and libraries:
fid=py.open(filename,'rb');
data=py.pickle.load(fid);
The contents of data will need to be converted from their respective python classes to those used by Matlab. For example, if data is a list then convert to a cell:
data=cell(data);
Similarly, dictionaries can be converted to strucures
data=struct(data)
And numpy arrays to doubles
data=double(data);
  8 个评论
Yun Guan
Yun Guan 2021-11-9
I use the "data=py.pickle.load(fid)" to read my pckl data, but it show"Python error ModuleNotFoundError: No module named 'numpy'" , have you some idea? thanks
Dev Sarma
Dev Sarma 2022-3-12
You have to make sure the numpy package is installed. You can install numpy from your command line 'python -m pip install numpy'. (or py instead of python). More information here: https://numpy.org/install/

请先登录,再进行评论。


Jan
Jan 2018-3-16
Did you take the time to search in the net before asking?
Does this help already? I do not find a Matlab code to interpret these Python pickle files.
  2 个评论
kc
kc 2019-12-31
these threds are not very useful sir, specially for ppl dnt know python
Walter Roberson
Walter Roberson 2019-12-31
The second link shows a few lines of Python needed to read the files and convert them to something usable by MATLAB.
The pickle format is python internal format that is not intended to be human readable, and is documented as not being compatible with other standards: https://docs.python.org/3/library/pickle.html
The data format used by pickle is Python-specific. This has the advantage that there are no restrictions imposed by external standards such as JSON or XDR (which can’t represent pointer sharing); however it means that non-Python programs may not be able to reconstruct pickled Python objects.
Thus you have python-specific datasets, and you would have a hard time reconstructing the data without using python.
See https://www.mathworks.com/help/matlab/call-python-libraries.html for information on calling python from MATLAB.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by