以下代碼:如何在python中實現matlab工作區中的基本循環?
eng = matlab.engine.start_matlab()
eng.eval('i=1;', nargout=0)
eng.eval('while i<10', nargout=0)
eng.eval('i=i+1', nargout=0)
eng.eval('end;', nargout=0)
eng.quit()
總是顯示以下錯誤:
Traceback (most recent call last):
File "while.py", line 13, in <module>
main()
File "while.py", line 7, in main
eng.eval('while i<10', nargout=0)
File "/Library/Python/2.7/site-packages/matlab/engine/matlabengine.py", line 84, in __call__
_stderr, feval=True).result()
File "/Library/Python/2.7/site-packages/matlab/engine/futureresult.py", line 68, in result
return self.__future.result(timeout)
File "/Library/Python/2.7/site-packages/matlab/engine/fevalfuture.py", line 82, in result
self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
SyntaxError: Error: At least one END is missing: the statement may begin here.
彷彿 '端;'語句不在Matlab工作區中執行。爲什麼?解決辦法是什麼 ?
你可以發送全部爲一行嗎? 'eng.eval('i = 1 \ n同時我<10 \ ni = i + 1 \ nend;',nargout = 0)''''''''''''''繼續.. – Aaron
沒有傢伙。由於'\ n',它無法工作。還請查看我對L. Scott Johnson的回答的評論。 –