Calling Matlab function from python: “initializer must be a rectangular nested sequence”

Calling Matlab function from python: “initializer must be a rectangular nested sequence”

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)])
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/119595.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • win10双系统重装ubuntu_双系统win10无法启动

    win10双系统重装ubuntu_双系统win10无法启动    这两天笔者安装win10+ubuntu16.04双系统,因为网络上能找到大量的资料,安装过程此处就不多讲。因为笔者电脑是华硕主板,bios默认设置为安全启动,笔者猜测会阻止加载ubuntu引导,导致双系统不能随意引导。先不管那么多,现在的问题是Ubuntu已经安装成功,开机直接进入win10,所以笔者的

    2022年10月21日
    0
  • 2017 cinemachine[通俗易懂]

    2017 cinemachine[通俗易懂]只有2017以上才可以使用~导入Assetstore中的cinemachine,会在上方显示cinemachine。每创建一个虚拟摄像机,就会在主摄像机下创建组件cinemachineBrain;虚拟摄像机的solo可以理解为把当前虚拟摄像机权重设置最高便于修改。cinemachineBrain属性:showdebugText会打印当前是哪个摄像机在执…

    2022年5月23日
    29
  • Java 构造函数的详解

    Java 构造函数的详解我们人出生的时候,有些人一出生之后再起名字的,但是有些人一旦出生就已经起好名字的。那么我们在java里面怎么在对象一旦创建就赋值呢?1.构造方法的作用:构造方法作用:对对象进行初始化.如图:2.构造函数与普通函数的区别:(1). 一般函数是用于定义对象应该具备的功能。而构造函数定义的是,对象在调用功能之前,在建立时,应该具备的一些内容。也就是对象的初

    2022年7月8日
    21
  • pycharm全局搜索代码_linux全局搜索字符串

    pycharm全局搜索代码_linux全局搜索字符串参考链接实测好用!我改为Ctrl+Shift+G也有冲突,把G随便换成其它无冲突的字母就可用了!

    2022年8月26日
    2
  • mysql只有information_schema_validationquery not set

    mysql只有information_schema_validationquery not set在MySQL8.0以前,通常会通过infomation_schema的表来获取一些元数据,例如从tables表中获取表的下一个auto_increment值,从indexes表获取索引的相关信息等。但在MySQL8.0去查询这些信息的时候,出现了不准确的情况。例如auto_increment,–此时test表的auto_increment是204mysql>showcreate…

    2022年9月16日
    0
  • 斑马条码打印机gk888t如何使用_斑马打印机gk888cn安装驱动教程

    斑马条码打印机gk888t如何使用_斑马打印机gk888cn安装驱动教程1、样子2、下载驱动,安装,一直next,next点击安装打印机,选择GK888t下一步,选择usb点击完成,进入下面页面安装文字然后一直下一步,下一步,直到完成。完成之后,进行测试。

    2022年8月3日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号