python呼叫matlab
1.首先需要安裝好matlab
確保在matlab的安裝路徑下/usr/local/MATLAB/R2016a/
有/extern/engines/python
這個資料夾,有了這個資料夾才能安裝python呼叫matlab的engine
2.呼叫
開啟matlab安裝目錄cd /usr/local/MATLAB/R2016a/extern/engines/python
執行安裝python setup.py install
如果提示許可權有問題,請切換到管理員許可權
3.測試
在你的目錄下新建一個測試檔案,例如cd /home/cj/document
vim test.py
然後按'i'進入編輯模式
貼上以下測試指令碼
import matlab
import matlab.engine
import time
def basic_test(eng):
print "Basic Testing Begin"
print "eng.power(100,2) = %d"%eng.power(100,2)
print "eng.max(100,200) = %d"%eng.max(100,200)
print "eng.rand(5,5) = "
print eng.rand(5,5)
print "eng.randi(matlab.double([1,100]),matlab.double([3,4]))"%\
eng.randi(matlab.double([1,100]),matlab.double([3,4]))
print "Basic Testing Begin"
def plot_test(eng):
print "Plot Testing Begin"
eng.workspace['data'] = \
eng.randi(matlab.double([1,100]),matlab.double([30,2]))
eng.eval("plot(data(:,1),'ro-')")
eng.hold('on',nargout=0)
eng.eval("plot(data(:,2),'bx--')")
print "Plot testing end"
def audio_test(eng,freq,length):
print "Audio Testing Begin"
eval_str = "f = %d;t=%d;"%(freq,length)
eng.eval(eval_str,nargout = 0)
eng.eval('fs = 44100;T=1/fs;t=(0:T:t);',nargout = 0)
eng.eval('y = sin(2 * pi * f * t);',nargout = 0)
eng.eval('sound(y,fs);',nargout = 0)
time.sleep(length)
print "Audio Testing End"
def fourier_test(eng):
pass
def demo(eng):
basic_test(eng)
plot_test(eng)
audio_test(eng,680,1)
if __name__ == "__main__":
print "Initializing Matlab Engine"
eng = matlab.engine.start_matlab()
print "Initializing Complete!"
demo(eng)
print "Exiting Matlab Engine"
print "Press Any Key to Exit"
raw_input();
eng.quit()
print "Bye-Bye"
如果貼上過程中自動縮排了的話要注意,不然一會兒執行就會報錯,避免讓其自動縮排的方法是
在貼上資料之前,輸入下面指定開啟paste模式
:set paste
貼上完畢後,輸入下面指定關閉paste模式
:set nopaste

image.png
然後就可以取消自動縮排啦!
然後按'esc'退出編輯模式
按':wq'儲存並退出

image.png
來到終端:
切換到剛剛測試檔案所在路徑cd /home/cj/document
python test.py
執行成功後,就可以出一個圖啦!說明呼叫成功!

image.png
相關文章
- matlab呼叫pythonMatlabPython
- python呼叫matlab程式,MATLAB 指令碼打包為 exe可執行程式PythonMatlab指令碼行程
- MATLAB VS PYTHONMatlabPython
- python與matlab混編PythonMatlab
- MATLAB呼叫NASTRAN的連續計算解決方案MatlabAST
- python 呼叫 webdriverPythonWeb
- matlab呼叫攝像頭並儲存成幀的形式Matlab
- 「Python」Numpy equivalent of MATLAB's cell arrayPythonUIMatlab
- Matlab轉python的索引問題MatlabPython索引
- C#呼叫PythonC#Python
- Java呼叫R與PythonJavaPython
- R呼叫python模組Python
- python ChainMap的呼叫效率PythonAI
- Python呼叫C/C++方式PythonC++
- C#呼叫python的方法C#Python
- C#/.net程式呼叫pythonC#Python
- C# 呼叫Python程式碼C#Python
- Java-呼叫R語言和呼叫Python(前後端展示)JavaR語言Python後端
- 使用PyO3從Python呼叫 Rust:加速PythonPythonRust
- python—呼叫API人臉識別PythonAPI
- springboot java呼叫flask python寫的Spring BootJavaFlaskPython
- Matlab、Julia與Python之間的對比 | Toby DriscollMatlabPython
- Python和Matlab有何區別?哪個更難?PythonMatlab
- Python呼叫C++編寫的方法PythonC++
- Python與C/C++呼叫之ctypesPythonC++
- swoole phpy PHP 與 Python 互呼叫庫PHPPython
- Python入門之函式呼叫(二)Python函式
- 教你如何利用python呼叫攝像頭Python
- Python呼叫飛書傳送訊息Python
- python爬蟲呼叫谷歌翻譯介面Python爬蟲谷歌
- Windows上Python使用swig呼叫C++WindowsPythonC++
- python呼叫hanlp分詞包手記PythonHanLP分詞
- python 呼叫通義千問SDK APIPythonAPI
- linux下qt用c++呼叫pythonLinuxQTC++Python
- 如何呼叫python中的shell指令碼?Python指令碼
- python中getattr如何帶引數呼叫?Python
- python和c++的相互呼叫教程PythonC++
- 在python程式中呼叫java程式碼PythonJava
- Python-呼叫執行系統命令Python