Reading python pickle of dict in MATLAB causes error
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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)])
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 Kommentare
Mohammad Sami
am 11 Mär. 2021
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
am 11 Mär. 2021
You can see this answer on how you can convert your dictionary into a Matlab type containers.Map.
Antworten (1)
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!