从Python到MATLAB的矩阵 [英] Matrix from Python to MATLAB

查看:1218
本文介绍了从Python到MATLAB的矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用Python和MATLAB,而且我有一个Python的二维数组,我需要写入一个文件,然后能够将它作为矩阵读入MATLAB。任何想法如何做到这一点?



谢谢!

解决方案如果您使用numpy / scipy,可以使用 scipy.io.savemat 函数:

  import numpy, scipy.io 

arr = numpy.arange(10)
arr = arr.reshape((3,3))#2d数组3x3

scipy。 io.savemat('c:/tmp/arrdata.mat',mdict = {'arr':arr})

现在,您可以使用File - > Load Data将这些数据加载到MATLAB中。选择文件并在您的环境中使用 arr 变量(一个3x3矩阵)。

注意:I在scipy 0.7.0上做了这个。 (scipy 0.6在 scipy.io.mio 模块中有 savemat )请参阅了解更多详情的最新文档

编辑:更新链接感谢 @gnovice 。 p>

I'm working with Python and MATLAB right now and I have a 2D array in Python that I need to write to a file and then be able to read it into MATLAB as a matrix. Any ideas on how to do this?

Thanks!

解决方案

If you use numpy/scipy, you can use the scipy.io.savemat function:

import numpy, scipy.io

arr = numpy.arange(10)
arr = arr.reshape((3, 3))  # 2d array of 3x3

scipy.io.savemat('c:/tmp/arrdata.mat', mdict={'arr': arr})

Now, you can load this data into MATLAB using File -> Load Data. Select the file and the arr variable (a 3x3 matrix) will be available in your environment.

Note: I did this on scipy 0.7.0. (scipy 0.6 has savemat in the scipy.io.mio module.) See the latest documentation for more detail

EDIT: updated link thanks to @gnovice.

这篇关于从Python到MATLAB的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆