Transform a Dict (or any python data structure) to Struct or Cell Array in Matlab.
Afficher commentaires plus anciens
Hi,
I'd like to create a structure or a cell array from Matlab given a Python dictionary. I'm using the built-in Python API to call from Matlab a user-defined function I wrote in Python.
The function I wrote (saved in a file called 'py2mat.py') is like this:
def test(w,j,l):
array1 = np.array([w,j,l])
array2 = np.array(['a','b','c'])
array3 = np.array([1.01,2.02,3.03])
df = pd.DataFrame({'array1':array1, 'array2':array2,'array3':array3})
return df.to_dict()
To call in Matlab, I do this:
N=py.py2mat.test(2,4,5);
s=struct(N);
And everything's great, but... when I look into the struct, all I got is this data structure with nested dictionaries. So, how do I do to display the values of the dictionaries into struct fields or cell arrays for further manipulation?
I'd like to know.
Thanks a lot for your time!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!