How to call a MATLAB function from Python with a combination of variables from Python and MATLAB workspace?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
Biral Pradhan
el 1 de Sept. de 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:
0 comentarios
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!