Hướng dẫn python matlab simulink

Main Content

Write Python® programs that work with MATLAB®

Functions

expand all

Python Functions

MATLAB Functions

Topics

Installing

  • System Requirements for MATLAB Engine API for Python
    What you need to write and build MATLAB engine applications for Python.
  • Install MATLAB Engine API for Python

    To start MATLAB engine within a Python session, install the engine API as a Python package.

    • Python Setup Script to Install MATLAB Engine API
    • Install MATLAB Engine API for Python in Nondefault Locations

Getting Started

  • Get Started with MATLAB Engine API for Python
    The MATLAB Engine API for Python provides a Python package named matlab that enables you to call MATLAB functions from Python.
  • Start and Stop MATLAB Engine for Python
    Options for starting the MATLAB Engine for Python.
  • Call MATLAB Functions from Python
    How to return an output argument from a MATLAB function. How to read multiple outputs from a function. What to do when the MATLAB function does not return an output argument.
  • Get Help for MATLAB Functions from Python
    From Python, you can access supporting documentation for all MATLAB functions.

Data Exchange and Mapping

  • Use MATLAB Arrays in Python
    This example shows how to create a MATLAB array in Python and pass it as the input argument to the MATLAB sqrt function.
  • MATLAB Arrays as Python Variables
    The matlab Python module provides array classes to represent arrays of MATLAB numeric types as Python variables so that MATLAB arrays can be passed between Python and MATLAB.
  • Pass Data to MATLAB from Python
    When you pass Python data as input arguments to MATLAB functions, the MATLAB Engine for Python converts the data into equivalent MATLAB data types.
  • Handle Data Returned from MATLAB to Python
    When MATLAB functions return output arguments, the MATLAB Engine API for Python converts the data into equivalent Python data types.
  • Use MATLAB Handle Objects in Python
    This example shows how to create an object from a MATLAB handle class and call its methods in Python.
  • Default Numeric Types in MATLAB and Python
    MATLAB stores all numeric values as double-precision floating point numbers by default.

Calling MATLAB Functions

  • Call User Scripts and Functions from Python
    This example shows how to call a MATLAB script to compute the area of a triangle from Python.
  • Sort and Plot MATLAB Data from Python
    This example shows how to sort data about patients into lists of smokers and nonsmokers in Python and plot blood pressure readings for the patients with MATLAB.
  • Call MATLAB Functions Asynchronously from Python
    This example shows how to call the MATLAB sqrt function asynchronously from Python and retrieve the square root later.
  • Redirect Standard Output and Error to Python
    This example shows how to redirect standard output and standard error from a MATLAB function to Python StringIO objects.

Troubleshooting

Engineers who rely only on Python may find themselves encountering difficult or challenging tasks when it comes to embedded applications, building interactive dashboards, parallelizing applications, and deep learning. Contrarily, MATLAB® is a full-stack advanced analytics platform that empowers domain experts to rapidly prototype ideas, validate models, and push applications into production with ease; however, sometimes it is advantageous to integrate MATLAB and Python. One example is the need to combine the MATLAB library of advanced analytic capabilities with supplemental models available in the open source community. Another, using Python as a language that is well suited to pipe data between different IT systems or the web.

There are several ways to integrate MATLAB and Python either as R&D tools or as scalable components of your production infrastructure. The latter gives business users and decision-makers immediate access to many of the built-in analytic capabilities in MATLAB from deep learning, optimization, signal and image processing, computer vision, data mining, time-series forecasting, embedded code generation, and more.

Watch the many ways in which MATLAB and Python can interface and integrate with each other.

Highlights include:

  • Calling Python libraries directly from MATLAB
  • Calling Python from within a Simulink® model
  • Calling a live MATLAB session from Python
  • Package MATLAB analytics as royalty-free .py libraries
  • Scaling hybrid MATLAB and Python applications via MATLAB Production Server™