0

My definite goal is to update the real-time value to Matlab(simulink) from python to apply control system.

With separated processes, I get the real-time updating value. The value type is an integer.

I want to pass this updating value to Matlab workspace. So I tried using the command in Matlab workspace : pyrunfile('A.py')

However, As you see this link, 10th line of "Limitations to Python Support", https://fr.mathworks.com/help/matlab/matlab_external/limitations-to-python-support.html

Matlab doesn't support multiprocessing. In other words, if I try to run the python file from Matlab workspace, it doesn't work.

But multiprocessing is requisite for my work. (not working with multithread)

So my idea :

  1. Run the file A.py which contains multiprocessing.
  2. under A.py is still running, I pass the desired updating value to another file B.py with loop .
  3. Export this value to Matlab workspace.
  4. Matlab workspace -> simulink

Firstly , I would like to know whether it sounds feasible or not. if not, I would like to have some other workflow suggestion.

summary :

python -> matlab is not possible because of multiprocessing.

python -> ?? -> matlab , is there any other method?

1
  • To run two files simultaneously, you can use the command line: python A.py B.py.
    – OmegaO333
    Jul 26, 2022 at 23:42

1 Answer 1

0

I'm not sure if this is the most efficient way, but you could write the variable to a file and read it from the other file.

#Read file
with open("file.txt", "r") as txt_file:
    return txt_file.readlines()

#Open file
txt_file = open("file.txt", "w")
txt_file.write(var)
txt_file.close()

You can pass the values like that. I'm not sure how to do the rest, but i hope this helps

Also just make 2 instances of the command line, and run the files seperately to run both of them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.