Effacer les filtres
Effacer les filtres

How to call a MATLAB function from Python with a combination of variables from Python and MATLAB workspace?

3 vues (au cours des 30 derniers jours)
Hi,
I have a function I would like to run from Python that has as inputs a combination of variables currently in the MATLAB workspace and from Python. What is the best way to call the function with variables from both?
-Using the eng.workspace['MATLAB_Workspace_Variable'] in the eng.MATLABfunction python function call doesn't seem to work, as it seems like it wants to pass the variables to Python first, and I get errors saying "only a scalar can be returned from MATLAB."
-I could make the MATLAB variables I want to have be global and then call a script from python instead of the function itself, passing the python variables, but that seems clunky.
Is there a better method?

Réponses (1)

Biral Pradhan
Biral Pradhan le 1 Sep 2022
I understand you have a function written in python that requires input arguments both from python and MATLAB Workspace variables. I assume the MATLAB variables in your case are being returned by a MATLAB function. Based on the error message you mentioned, it might be most likely due to omission of the number of output arguments. Please check if the number of output arguments of the MATLAB function are specified using "nargout". In case of multiple return variables, a tuple is created in python. For more information, kindly follow the below documentation link:
I would also recommend to check if the data types returned by MATLAB are supported by Python. Kindly follow the below documentation for more information:

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by