Passing path as input argument in matlab.engine
20 ビュー (過去 30 日間)
古いコメントを表示
I'm using the following lines of code to run main.m (I:/xxx/simcode/xxx/main) with path as input argument, using matlabe engine
import matlab.engine
eng = matlab.engine.start_matlab()
eng.run("I:/xxx/simcode/xxx/main, ['I:/xxx/xxxx/xxx/task5'])
eng.quit()
But I get an error,
self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
matlab.engine.MatlabExecutionError: Too many input arguments.
Could someone please suggest how to fix this?
I would like to run the main.m from python by passing an input argument which is a path.
採用された回答
Steven Lord
2023 年 6 月 18 日
The run function in MATLAB accepts only one input, the name of a script file. Is your main.m a script file or a function file? If the former it cannot accept input arguments; that's one of the defining characteristics of a script! If it's a function file, I think you can run it directly with something like (untested)
import matlab.engine
eng = matlab.engine.start_matlab()
eng.main("['I:/xxx/xxxx/xxx/task5']")
eng.quit()
Or if you need to change directories before calling your function, call cd then call feval in your MATLAB Engine session.
Note that I haven't used this functionality directly, I'm just going by what I see in the documentation.
4 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call MATLAB from Python についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!