五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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的方法的評論 (共 條)

分享到微博請遵守國家法律
北川| 福贡县| 策勒县| 辽源市| 建平县| 沂水县| 南郑县| 电白县| 宜兰县| 南陵县| 老河口市| 屏边| 滁州市| 莱西市| 天长市| 达日县| 祁连县| 雅安市| 卫辉市| 宜阳县| 民权县| 广饶县| 彝良县| 南和县| 佛坪县| 巢湖市| 渝北区| 蓬莱市| 莱州市| 炉霍县| 九江县| 张家口市| 成安县| 资兴市| 化德县| 平阳县| 永昌县| 克山县| 永顺县| 景宁| 延边|