Py学习  »  Python

从Python运行Matlab脚本:TypeError:“float”对象不可iterable

Thang Ha • 4 年前 • 142 次点击  

实际上,我在从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

任何人请给我答案。提前非常感谢。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50681
 
142 次点击  
文章 [ 1 ]  |  最新文章 4 年前