实际上,我在从Python调用Matlab脚本时遇到了问题。
import matlab.engine
import os
import random
import numpy as np
a=[str(random.randint(1,3)) for _ in range(3)]
print(a)
eng=matlab.engine.start_matlab()
eng.cd("/Users/dha/Documents/MATLAB/test-matlab/",nargout=0)
sr, state=eng.test_func()
print(sr)
print(state)
实际上,我想返回“sr”,它是一个浮点数和一个整数“state”数组,例如sr=34.31和state=[1,2,5]。函数test_func()在Matlab上运行得很好,但当我从终端(Python test_Matlab_engine.py)在Python中运行它时,收到以下错误:
Traceback (most recent call last):
File "test_matlab_engine.py", line 10, in <module>
sr, state=eng.mabuc_drl(a)
TypeError: 'float' object is not iterable
任何人请给我答案。提前非常感谢。