Python executes matlab files

Source: Internet
Author: User

Environment: Matlab2014b,mac Os,python 2.7

1. Windows users can use win32com,com only for Windows systems, where there is no attempt.

2. If you are performing a simple command, you can use the engine provided by matlab2014b, my/applications/matlab_r2014b.app/extern/engines/python.

# # #Matlab Engine for Python
#Call Matlab Function from Python

------------------------------
# #Step 1:installation

#Install with Administrator privileges
CD "Matlabroot\extern\engines\python"
Python setup.py Install

#Install without Administrator privileges

CD "Matlabroot\extern\engines\python"
Python setup.py build--build-base builddir install--install-base installdir

Include ' InstallDir ' in the search path for Python packages
Add ' InstallDir ' to the PYTHONPATH environment Variavle


------------------------------
# #Step 2:using Matlab Engine

#Start and quit
Import Matlab.engine
ENG = Matlab.engine.start_matlab ()
Eng.quit ()

#Call Matlab Functions:
#Just Call with Form eng.xxx ()
#the function xxx should in the namespace of Matlab.


#Asynchronously Call
Import Matlab.engine
ENG = Matlab.engine.start_matlab ()
Future = Eng.sqrt (4.0,async=true)
ret = Future.result ()
Print (ret)


#WorkSpace Usage:
Import Matlab.engine
ENG = Matlab.engine.start_matlab ()
eng.workspace[' y '] = X
A = Eng.eval (' sqrt (y) ')
Print (a)


#Skills for unsupported features in Python
#eng. Eval ()
Import Matlab.engine
ENG = Matlab.engine.start_matlab ()
Eng.eval ("T = readtable (' Patients.dat ');", nargout=0)

#Plot with Matlab:
Import Matlab.engine
ENG = Matlab.engine.start_matlab ()
data = Eng.peaks (100)
Eng.mesh (data)
------------------------------

3. Python calls execute MATLAB directly, there are many tools available:

3.1. Pymat

No python2.7 support.

3.2. Pymat2

Improved on the basis of Pymat.

3.3. Mlabwrap

http://mlabwrap.sourceforge.net/

Root permission is required. Initial installation unsuccessful, reported OSError: [Errno 2] No such file or directory, should be unable to find the path of matlab2014b, Change path plus MATLAB installation directory succeeds (changing the installation parameters in setup.py should also be possible, not attempted). Export Path=/applications/matlab_r2014b.app/bin: $PATH

Import Mlabwrap as Mlab when also reported import Mlabraw unsuccessful, Google found export dyld_library_path=/applications/matlab_r2014b.app/ bin/maci64: $DYLD _library_path,

Here the runmodel.m file content is function result = Runmodel () ..... END

Call Mode Mlab.runmodel ()

The solution references the http://stackoverflow.com/questions/13311415/run-a-matlab-script-from-python-pass-args/13316939#13316939

http://sourceforge.net/p/mlabwrap/mailman/message/26145026/

3.4. Mlab

Seems to be unstable on the Mac, do not give up after the implementation.

3.5. Python-matlab-bridge

Https://github.com/jaderberg/python-matlab-bridge

Only work on Unix, and was based on TCP transmission while messages be decoded in JSON format.

3.6. Nipype

Http://nipy.sourceforge.net/nipype/api/generated/nipype.interfaces.matlab.html

Python executes matlab files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.