Reading python pickle of dict in MATLAB causes error

조회 수: 11 (최근 30일)
BABA CHOUDHURY
BABA CHOUDHURY 2021년 3월 11일
답변: Asvin Kumar 2021년 3월 15일
I have a pickle file of a python dictionary whose keys are tuples `(10, 11), (10, 12), (11, 10), (11, 12), (12, 10), (12, 11)`.
I use the following commands to read them
fid = py.open('file.pickle','rb');
data = py.pickle.load(fid);
At this point, I think the code is working correctly as
data.keys()
in MATLAB gives the correct answer as
dict_keys([(10, 11), (10, 12), (11, 10), (11, 12), (12, 10), (12, 11)])
The equivalent of dict in python is structures ([1]) so when I try to convert it to `struct` using
data=struct(data)
, I get an error as
Error using py.dict/struct
Field names must be non-empty character vectors or a string
scalars.
What does the error mean here?
  댓글 수: 4
Mohammad Sami
Mohammad Sami 2021년 3월 11일
Based on the output you have shown in your question, the keys are numeric values. As stated in the documentation matlab struct does not support these as field names. (see valid fieldname criteria)
Mohammad Sami
Mohammad Sami 2021년 3월 11일
You can see this answer on how you can convert your dictionary into a Matlab type containers.Map.

댓글을 달려면 로그인하십시오.

답변 (1개)

Asvin Kumar
Asvin Kumar 2021년 3월 15일
Map containers might be what you're looking for.

카테고리

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