Hướng dẫn matlab python package
Main Content Show
Write Python® programs that work with MATLAB® Functionsexpand all Python FunctionsMATLAB FunctionsTopicsInstalling
Getting Started
Data Exchange and Mapping
Calling MATLAB Functions
TroubleshootingSupported platforms: Windows®, Linux®, Mac This example shows how to create a Python® package from a MATLAB® function and integrate the generated package into a Python application. Prerequisites
Create Function in MATLABIn MATLAB, examine the MATLAB code that you want packaged. For this example, create a function named function y = makesqr(x)
y = magic(x); At the MATLAB command prompt, enter The output is a 5-by-5 matrix. 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 Create Python Application Using Library Compiler AppCompile the function into a Python package using the Library Compiler app. Alternatively, if you want to create a Python package from the MATLAB command window using a programmatic approach, see Create Python Package Using compiler.build.pythonPackage.
Specify Package SettingsNext, define the name of your Python package.
Create Sample Driver FileYou can add MATLAB files to the project to generate sample Python driver files. Although Python driver files are not necessary to create a package, you can use them to implement a Python application, as shown in Install and Run MATLAB Generated Python Application. In the Samples section, select Create New Sample, and click % Sample script to demonstrate execution of function y = makesqr(x) x = 0; % Initialize x here y = makesqr(x); Change For more information and limitations, see Sample Driver File Creation. Customize the Application and Its AppearanceIn the Library Compiler app, you can customize the installer, customize your application, and add more information about the application.
Package the ApplicationWhen you are finished selecting your packaging options, save your Library Compiler project and generate the packaged application.
Create Python Package Using compiler.build.pythonPackageAs an alternative to the Library Compiler app, you can create a Python package using a programmatic approach. If you have already created a package using the Library Compiler, see Install and Run MATLAB Generated Python Application.
Install and Run MATLAB Generated Python ApplicationAfter creating your Python package, you can call it from a Python application. This example uses the sample Python code generated during packaging. You can use this sample Python application code as a guide to write your own application.
See Also
Related Topics
|