国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

在python中調(diào)用MATLAB的方法

2020-04-26 14:45 作者:-PCon-  | 我要投稿

一些比較古早的方法建議在python中安裝mlab庫來實現(xiàn)調(diào)用的,這個方法已經(jīng)淘汰不用了,這里介紹比較新的方法。

Step 1: install MATLAB Engine API for Python

官網(wǎng)給出的方案:

install MATLAB Engine API for Python (http://ww2.mathworks.cn/help/matlab/matlab_external/install-the-matlab-engine-for-python.html?ue)

在MATLAB中輸入:

matlabroot

得到返回的位置

打開anaconda,輸入下面語句進行安裝

cd matlabroot\extern\engines\python
python setup.py install

注意要將matlabroot替換為之前返回的位置

Step 2: Call User Script and Function from Python

官網(wǎng)給出的方案:

Call User Script and Function from Python (http://cn.mathworks.com/help/matlab/matlab_external/call-user-script-and-function-from-python.html)

.m腳本的調(diào)用

.m文件與.py文件需要放在同一目錄下。在test.m文件中輸入:

b=2;
h=3;
a=b*h

在H.py文件中輸入:

import matlab.engine
eng = matlab.engine.start_matlab()
eng.test(nargout=0)

其中指定 nargout=0。盡管腳本會打印輸出,但它不會向 Python 返回任何輸出參數(shù)。

自定義函數(shù)的調(diào)用

在time.m中輸入:

function a = time(b,h)
a = b*h;
end

在H.py中輸入:

import matlab.engine
eng = matlab.engine.start_matlab()
ret = eng.time(1.0,5.0)
print(ret)

可以實現(xiàn)函數(shù)的調(diào)用。由于函數(shù)僅返回一個輸出參數(shù),因此無需指定 nargout

?2019?年?04?月?26?日

Txing


在python中調(diào)用MATLAB的方法的評論 (共 條)

分享到微博請遵守國家法律
南召县| 淳化县| 贵阳市| 尤溪县| 台南县| 湖南省| 岳阳市| 宁远县| 民县| 台安县| 大石桥市| 江源县| 九龙城区| 和顺县| 湾仔区| 磐石市| 房山区| 南澳县| 建湖县| 米泉市| 北流市| 溧水县| 酒泉市| 秦皇岛市| 临泽县| 湖北省| 阿拉善左旗| 阿克苏市| 韶山市| 卢龙县| 宜昌市| 武安市| 增城市| 大厂| 海南省| 鸡泽县| 博客| 青田县| 兴安县| 香港 | 杨浦区|