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)])

Calling Matlab function from python: “initializer must be a rectangular nested sequence”的更多相关文章

  1. Libsvm:脚本(subset.py、grid.py、checkdata.py) | MATLAB/OCTAVE interface | Python interface

    1.脚本 This directory includes some useful codes: 1. subset selection tools. (子集抽取工具) subset.py 2. par ...

  2. Python的扩展接口[3] -> Matlab引擎 -> 使用 Python 调用 Matlab 程序

    Python - Matlab 目录 Python-Matlab 引擎 Python-Matlab 数组 Python-Matlab 基本操作 Python-Matlab 调用 m 文件 Matlab ...

  3. initialize myObject by calling a function that returns an object literal

    w作用域控制变量的可见范围. JavaScript: The Good Parts Instead of initializing myObject with an object literal, w ...

  4. [CentOS Server] Bug when calling matlab in bash

    尝试了好几遍,仍然不能用简写命令调用matlab,这里把过程记录如下. (1). 登录 server [She@She ~]$ ssh shecl@xx.xx.xx.xx Last :: from x ...

  5. Matlab function lorenzgui

    function lorenzgui %LORENZGUI Plot the orbit around the Lorenz chaotic attractor. % This function an ...

  6. TypeError: 'encoding' is an invalid keyword argument for this function 解决Python 2.7

    在python2.7中这样调用代码 open('file/name.txt','r',encoding= 'utf-8').read() 会出现 TypeError: 'encoding' is an ...

  7. 解决方法:loadrunner 场景下执行webservice脚本是---报错10492 Error: Exception was raised when calling per-process-init function in extens

    在vug下执行时,脚本无异常,但是在controller下执行时报下面错误,网上查了下,解决方法千奇百怪,但无一可行. 分析了下错误,似乎是初始化进程有关.想到rts中的设置习惯时以线程方式执行. 遂 ...

  8. [Python-MATLAB] 在Python中调用MATLAB的API

    可以参考官方的说明文档: http://cn.mathworks.com/help/matlab/matlab_external/get-started-with-matlab-engine-for- ...

  9. Python调用Matlab2014b引擎

    用惯Python的你,是不是早已无法忍受matplotlib那丑陋无比的图以及蛋疼无比部署依赖? 当当当当,Matlab2014b的Python Engine API现已加入豪华午餐. 上次写了一篇文 ...

随机推荐

  1. postgresql 唯一约束增强

    http://blog.chinaunix.net/uid-15145533-id-2775821.html

  2. 从零开始学 Web 之 Ajax(二)PHP基础语法

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  3. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十四):项目打包部署

    项目打包部署 安装MySQL镜像 注意:如果使用docker镜像安装MySQL,也需要在前端部署主机安装MySQL,因为备份还原功能是使用MySQL的本地命令进行操作的. 下载镜像 执行以下命令,拉取 ...

  4. kafka server管理

    kafka启动以来zookeeper  kafka启动之前,首先要启动zookeeper 1.1.kafka启动单个节点 -daemon 表示程序以守护进程的方式后台云心 --override pro ...

  5. leetcode — two-sum-iii-data-structure-design

    import java.util.HashMap; import java.util.Map; /** * Source : https://oj.leetcode.com/problems/two- ...

  6. #10 Python字符串

    前言 通过上一节可知,Python6个序列的内置类型中,最常见的是列表和元组,但在Python中,最常用的数据类型却不是列表和元组,而是字符串.要想深入了解字符串,必须先掌握字符编码问题.因此本篇博文 ...

  7. WPF 使用 Direct2D1 画图入门

    本文来告诉大家如何在 WPF 使用 D2D 画图. 本文是一个系列 WPF 使用 Direct2D1 画图入门 WPF 使用 Direct2D1 画图 绘制基本图形 WPF 使用 SharpDX WP ...

  8. WebForm 【上传图片--添加水印】

      对图片添加水印,上传 <div> <asp:FileUpload ID="FileUpload1" runat="server" /> ...

  9. CheckBox-复选框-删除-选中行

    <!--删除选中的行,利用oTable.deleteRow(i)方法--> <!DOCTYPE html> <html xmlns="http://www.w3 ...

  10. repository和repertory

    在研究.net core的时候知道了仓储这个概念,并发现两个单词repository和repertory 两者都有仓库,储藏所,储藏的意思,repository还指知识渊博的人,repertory除了 ...