How to pass a structure from Matlab to Python
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jason Shih
le 3 Juil 2015
Réponse apportée : Jason Shih
le 8 Juil 2015
I'm using Matlab(2014b) and Python(2.7.6) for mix programming. I tried to pass a structure from Matlab to Python,but I failed.
The structure I want to pass is:
dmodel = struct('regr',regr, 'corr',corr, 'theta',theta.', ...
'beta',fit.beta, 'gamma',fit.gamma, 'sigma2',sY.^2.*fit.sigma2, ...
'S',S, 'Ssc',[mS; sS], 'Ysc',[mY; sY], ...
'C',fit.C, 'Ft',fit.Ft, 'G',fit.G);
In the structure all the elements are scalar except Ssc and Ysc.
The Matlab script looks like this:
function model=Fun_mat()
...
some command;
...
model = dmodel;
end
and the Python script looks like this:
import matlab.engine as meng
eng = meng.start_matlab()
dmodel = eng.Fun_mat()
eng.quit()
These two scripts are in the same directory.
What should I do? Any help is appreciate!
0 commentaires
Réponse acceptée
Gareth Thomas
le 5 Juil 2015
Hi Jason,
Have you seen this page in the R2015a documentation:
Please note that this is used for the MATLAB engine which can be called from python. I hope that this helps you.
Best regards, Gareth
1 commentaire
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Call MATLAB from Python dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!