Python调用MATLAB Install MATLAB Engine for Python

注意需要 Python是2.7, 3.3, and 3.4.噢

第一步:

用管理员权限打开cmd.exe

第二步:cd到MATLAB安装文件中的"\extern\engines\python"

第三步输入Python的安装目录+Python.exe setup.py install如下图


 另外有人说要改环境变量,按照上面的教程不行就改改环境变量吧


另外粘一段MATLAB官方使用教程

Call User Script and Function from Python

This example shows how to call a MATLAB® script to compute the area of a triangle from Python®.

In your current folder, create a MATLAB script in a file named triarea.m.

b = 5;
h = 3;
a = 0.5*(b.* h)

After you save the file, start Python and call the script.

import matlab.engine
eng = matlab.engine.start_matlab()
eng.triarea(nargout=0)
a =

    7.5000

Specify nargout=0. Although the script prints output, it returns no output arguments to Python.

Convert the script to a function and call the function from the engine. Open the MATLAB editor to edit the file.

eng.edit('triarea',nargout=0)

Delete the three statements. Then add a function declaration and save the file.

function a = triarea(b,h)
a = 0.5*(b.* h);

Call the new triarea function from the engine.

ret = eng.triarea(1.0,5.0)
print(ret)
2.5

The triarea function returns only one output argument, so there is no need to specify nargout.



相关博客整理如下

http://blog.sina.com.cn/s/blog_57a1cae80101osbj.html

http://www.cnblogs.com/Vonng/p/4239822.html?utm_source=tuicool&utm_medium=referral


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值