error in calling python function from matlab

2 views (last 30 days)
puneet sharma
puneet sharma on 16 Nov 2021
Commented: Yongjian Feng on 20 Nov 2021
Hi all,
I am trying to run a python function which is in Raspberry pi from MATLAB but I am getting this error.
when I call the same function directly from Raspberry terminal I got the output. but from MATLAB i am getting this error.
ps - I called the python *script* in raspberry pi from MATLAB i got the result.
If anyone can tell me How I can call python *function* from MATLAB in raspberry pi.
please find the screenshot attached.
python function in raspberry --- def add(x,y):
return x+y

Answers (1)

Yongjian Feng
Yongjian Feng on 20 Nov 2021
I am confused here. This doesn't look like valid python3 statements.
import /home/pi/Desktop/plus;
plus.add(150, 110)
Do you mean import; plus.add(150,110)?
Yongjian Feng
Yongjian Feng on 20 Nov 2021
Yes, from matlab system command actually runs the string input as a system command. As you can see from the second line of the error message, matlab tries to run the following from your command line:
sudo python3 -c "import /home/pi/Desktop/plus; plus.add(150, 110)"
Then the above doesn't look like a valid command line command. Python3 doesn't like the way you import the package.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!