How can i open dataset in matlab which is .pkl format?
조회 수: 377 (최근 30일)
이전 댓글 표시
답변 (2개)
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
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
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
2018년 3월 16일
Did you take the time to search in the net before asking?
- https://xcorr.net/2013/06/12/load-pickle-files-in-matlab/
- https://stackoverflow.com/questions/25859968/in-matlab-how-to-read-python-pickle-file
Does this help already? I do not find a Matlab code to interpret these Python pickle files.
댓글 수: 2
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 Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!