Calling Matlab function from python: “initia…
2018-06-28 05:39:00来源:博客园 阅读 ()
I am writing a python script from which I hope to call the Matlab anovan function. I have attempted a basic test of this feature on file test.txt.
This file is imported as array data
. In matlab, the anovan function would be called as follows:
anovan(data(:,1),{data(:,2),data(:,3)})
In python, I have attempted to call the function like this:
import matlab.engine
eng = matlab.engine.start_matlab()
data = np.genfromtxt('test.txt')
eng.anovan(matlab.double(data[:,0]),matlab.int8(data[:,1:2]))
Unfortunately, this gives the following error:
ValueError: initializer must be a rectangular nested sequence
I can see that there is some issue in passing the last two array columns to the function, but am unsure of the solution. Any suggestions would be appreciated.
I have now worked this out. The issue was in the format of the data passed to the function.
#convert grouping columns to integer lists
list1 = data[:,1].tolist()
for i in range(0,len(list1)):
list1[i] = int(list1[i])
list2 = data[:,2].tolist()
for i in range(0,len(list2)):
list2[i] = int(list2[i])
#The following command now works
eng.anovan(matlab.double(data[:,0].tolist()),[matlab.int8(list1),matlab.int8(list2)])
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:turtle绘图窗体布局
- python函数 2019-07-24
- 【Flask】报错解决方法:AssertionError: View function map 2019-04-20
- [python][matlab]使用python调用matlab程序 2019-03-10
- Django的FBV和CBV 2019-03-06
- Flask之endpoint错误View function mapping is overwriting 2018-12-17
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash