How do I interact with MATLAB from Python?

前端 未结 4 1557
深忆病人
深忆病人 2020-12-13 14:34

A friend asked me about creating a small web interface that accepts some inputs, sends them to MATLAB for number crunching and outputs the results. I\'m a Python/Django deve

相关标签:
4条回答
  • 2020-12-13 14:46

    As an alternative, since Matlab R2014b, a Python library is provided to call Matlab from Python using the MATLAB Engine API for Python.

    0 讨论(0)
  • 2020-12-13 14:50

    Regarding OS compatibility, if you use the matlab version for Linux, the scripts written in windows should work without any changes. If possible, you may also consider the possibility of doing everything with python. Scipy/numpy with Matplotlib provide a complete Matlab replacement.

    0 讨论(0)
  • 2020-12-13 14:51

    There is a python-matlab bridge which is unique in the sense that Matlab runs in the background as a server so you don't have the startup cost each time you call a Matlab function.

    it's as easy as downloading and the following code:

    from pymatbridge import Matlab
    mlab = Matlab(matlab='/Applications/MATLAB_R2011a.app/bin/matlab')
    mlab.start()
    res = mlab.run('path/to/yourfunc.m', {'arg1': 3, 'arg2': 5})
    print res['result']
    

    where the contents of yourfunc.m would be something like this:

    %% MATLAB
    function lol = yourfunc(args)
        arg1 = args.arg1;
        arg2 = args.arg2;
        lol = arg1 + arg2;
    end
    
    0 讨论(0)
  • 2020-12-13 14:52

    Take a look at mlabwrap which allows you to call Matlab via a python API

    0 讨论(0)
提交回复
热议问题