Running python script in C S-function Simulink

7 visualizaciones (últimos 30 días)
Sergio Mesa Martín
Sergio Mesa Martín el 5 de Jul. de 2021
Comentada: Sergio Mesa Martín el 6 de Jul. de 2021
I have been trying to run python scripts in matlab using the matlab function "system", but it gives me the output at the end of the script execution. I wanted to extract that output in real-time to proccess it in Simulink, so, is there any way to implement it for that purpose in a C-Sfunction?
That script uses variables from different python scripts and sends the output via print and not return.

Respuestas (1)

Yongjian Feng
Yongjian Feng el 5 de Jul. de 2021
Can you change your python code to write to a file? Then your matlab code can read from the file to get the output.
  3 comentarios
Yongjian Feng
Yongjian Feng el 6 de Jul. de 2021
Use that as a lock. The python code needs a while-loop to wait for the file to be available to write. Same thing in the matlab code. Use a while loop to wait for the file to be avaliable to read. Both side shall release the handle once it is done with reading/writing.
Sergio Mesa Martín
Sergio Mesa Martín el 6 de Jul. de 2021
I will try this. Is there any way to share a boolean variable between the python script and matlab to sinchronize the avalaibility of reading/writing, or any other way to tell the other side that they are done?

Iniciar sesión para comentar.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by