-------------------------------------------------------------------------------------------------
This article briefly introduces the. m file called Matlab by Python.
-----------------------------------------------------------------
first, the required tools
1. Python Development Environment (this article uses the "ANACONDA2" Integrated development Environment)
--Anaconda2 Download Address: Link: http://pan.baidu.com/s/1qXT7Mna Password: DQSF
2. Matlab (this article uses matlab2016a)
3. mlab-1.1.4
--Download Address: Link: http://pan.baidu.com/s/1bQC2j8 Password: 7NPG
4. pywin32-220.win-amd64-py2.7 (note here to be consistent with the Python version)
--Download Address: Link: http://pan.baidu.com/s/1eRPi2Ca password: 1MQR Two, the environment constructs
1. Install MATLAB, Anaconda2 (this is mainly to build Python environment), this part of this article does not do detailed introduction.
2. Installation and configuration of Mlab:
--Mlab File structure: mainly includes [Mlab.egg-info] [SRC] [setup.py]
--Copy the relevant files under the Mlab file to the same root directory as Python.exe (this step is because I have 2 versions of Python installed on my computer, and I enter Python calls under CMD or PowerShell not the inheritance environment Anaconda2 python)
--Execute ". \python.exe. \setup.py install" To start the installation, the results are as follows:
3. Installation of pywin32-220.win-amd64-py2.7:
--Execute "pywin32-220.win-amd64-py2.7.exe"
--The program automatically generates the path, as follows:
-then go directly to the next step until the installation is complete.
Third, the example explains:
1. Matlab code: "GET_SUM.M"
function Sum_ab = get_sum (a,b)
Sum_ab = double (A + B);
End
2. Python code: "pythonmatlab.py"
#-*-Coding:utf-8-*-
from mlab.releases import latest_release as Matlab
Matlab.path (Matlab.path (), R ' C:\Users \administrator\desktop\python_matlab ') #设置路径
def mainfunction ():
a = Int (1)
b = Int (2) Result
= Matlab.get_sum (A, b) # call MATLAB's function
print result
#=======================================
if __name__ = ' __main__ ':
print ' running ... '
mainfunction ()
3. Execute in the Python directory:
--use "PowerShell" to enter the root directory of Python.exe: C:\Program files\anaconda2
--Execute Python file:. \python.exe. \pythonmatlab.py
--The results are as follows:
--------------------------------
Follow-up will consider introducing a more specific application (face recognition):
1. MATLAB Trains the neural network, and provides the function interface (including accepting two different pictures), and returns the result.
2. Python calls OpenCV to implement face clipping, and invoke the. m file provided by Matlab.
3. Show results: Whether the two faces belong to the same person.
--------------------------------