Why do I receive an "Invalid User of Operator Error" when calling function from command line?

I have a code in matlab titled "original_boresight_verification.m" located in a directory "C:\Users\17037\Documents\Code\Matlab\resepi_boresighting". It inputs a file location (as a string), and outputs a single line of numbers (separated by commas) to the command window. It does not return any values.
I need to run this code from a python script and am using the subprocess command, which I have tested (that part "should" be working). When I run this in the command window:
I receive an "Invalid Use of Operator" error. I do not know why. When running the code in the Matlab command window:
I receive no errors, works perfectly fine. If it would help I can upload the code, although it is fairly lengthy so I will not unless it would be helpful.
My question: Why am I receiving an error in the python script calling the matlab function when the matlab function works perfectly fine?
Any help would be greatly appreciated. Thank you :)

 채택된 답변

I figured it out and am posting the answer in case anyone else has this problem:
I had an extra semicolon after original_boresight_verification. It was this:
subprocess.run(['matlab', '-batch', 'original_boresight_verification; C:\\Users\\17037\\Documents\\35844\\ROCK-537F25-2021-08-24-20-25-08\\clouds\\ppk_cloud_1.las'], capture_output=True, text=True, cwd=working_dir)
and now it is:
subprocess.run(['matlab', '-batch', 'original_boresight_verification C:\\Users\\17037\\Documents\\35844\\ROCK-537F25-2021-08-24-20-25-08\\clouds\\ppk_cloud_1.las'], capture_output=True, text=True, cwd=working_dir)
This was causing varargin to have multiple inputs whereas it should only have one. Not sure why this returned an "Invalid use of operator" error though.
If you are having a similar problem I would suggest the following steps to work through the problem (this is what I did):
  1. Check your function works in Matlab
  2. Check your function works in the command window (by itself not with python): use "cd 'path'" to navigate to the directory of your matlab file, then try
>matlab -batch "function_name argument_go_here"
Once this works go back and put it in python using the subprocess module (do not forget to import it), it should work now. :)

댓글 수: 1

if any of the moderators know why it gives an "Invalid use of operator" error, I would be interested to know why

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2020b

질문:

2021년 8월 26일

댓글:

2021년 8월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by