Running python script in C S-function Simulink

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.

답변 (1개)

Yongjian Feng
Yongjian Feng 2021년 7월 5일

0 개 추천

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

I tried this, but if I read the file while the script is executing (using csvread), it stops its execution because another proccess is using it, so it can no longer write in that file to be read by matlab, being impossible to do real-time proccessing.
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.
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?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 7월 5일

댓글:

2021년 7월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by