How to import Pickle data using Python Interface
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 30 Mai 2023
Beantwortet: MathWorks Support Team
am 30 Mai 2023
I created data in Python and serialized it in a Pickle file using the following code.
import pickle
# Create a Python dictionary whose values are tuples
data = {'x': (1, 2, 3), 'y': (3.1, 4.2, 5.3)}
with open('data.pickle','wb') as f:
pickle.dump(data,f,pickle.HIGHEST_PROTOCOL)
How can I load and use this data in MATLAB?
Akzeptierte Antwort
MathWorks Support Team
am 30 Mai 2023
You can load Pickle-formatted data into MATLAB by using Python Interface . To call Python modules from MATLAB you must first configure your system to use Python . Note that Pickle is preinstalled with Python 3.x and does not need to be installed.
To load your Pickle data into MATLAB, execute these commands.
>> fid = py.open('data.pickle','rb');
>> data = py.pickle.load(fid)
data =
Python dict with no properties.
{'x': (1, 2, 3), 'y': (3.1, 4.2, 5.3)}
For more information on how to work with the imported data, see Handle Data Returned from Python Function and Access Elements in Python Container Types . For example, the following code creates a MATLAB double array from the dictionary 'y' value.
>> y = double(data{"y"})
y =
3.1000 4.2000 5.3000
0 Kommentare
Weitere Antworten (0)
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!