How to Upload Matlab Code Into Github
Creating Python package from MATLAB lawmaking using SDK compiler
This example shows how to create a Python package using a MATLAB function. You tin and so pass the generated package to the developer, who is responsible for integrating information technology into an awarding.
To compile a Python packet from MATLAB lawmaking, follow the following steps one by one.
-
In MATLAB, examine the MATLAB code that yous want to deploy equally a Python parcel. The example used hither is makesqr.m, located in matlabroot\toolbox\javabuilder\Examples\MagicSquareExample\MagicDemoComp
a. Open makesqr.m.
function y = makesqr(ten) y = magic(x);
b. At the MATLAB control prompt, enter addition(67, iii).
The output appears as follows:
ans = eight 1 6 3 v seven four 9 2
-
Open the Library Compiler app.
a. On the toolstrip, select the Apps tab.
b. Click the arrow at the far right of the tab to open up the apps gallery.
c. Click Library Compiler.
-
In the Application Blazon section of the toolstrip, select Python Package from the list.
-
Specify the MATLAB functions yous want to deploy.
a. In the Exported Functions section of the toolstrip, click the plus button.
b. In the file explorer that opens, locate and select the makesqr.m file.
makesqr.chiliad is located in matlabroot\toolbox\javabuilder\Examples\MagicSquareExample\MagicDemoComp.
c. Click Open to select the file, and close the file explorer.
makesqr.m is added to the list of exported files and a minus push button appears under the plus push button. In improver, makesqr is set as the package name.
-
In the top field of Application Information, replace Library Name makesqr with MagicSquarePkg.
For more than data on naming requirement for the Python package, meet Import Compiled Python Packages.
-
In the Packaging Options section of the toolstrip, verify that the Runtime downloaded from web check box is selected.
This option creates an application installer that automatically downloads the MATLAB Runtime and installs it along with the deployed bundle.
-
Click Save to specify a projection proper name and save the project.
-
Click Bundle.
-
Select the Open output folder when process completes check box.
-
Verify that the generated output contains:
-
for_redistribution — A binder containing the installer to distribute the parcel
-
for_testing — A folder containing the raw generated files to create the installer
-
for_redistribution_files_only — A folder containing only the files needed to redistribute the packet
-
PackagingLog.txt — A log file generated by the compiler
-
-
Click Close on the Package window.
-
Open a control prompt in the for_redistribution_files_only folder.
-
Run the setup script to install the package.
python setup.py install
-
Create a new file called getmagic.py. Paste the post-obit code into the file.
import MagicSquarePkg myMagic = MagicSquarePkg.initialize() print(myMagic.makesqr(3)) myMagic.finish()
-
From the organization's command prompt, run the application.
python getmagic.py
The following output will be displayed:
[[eight.0,i.0,six.0], [3.0,5.0,7.0], [4.0,9.0,2.0]]
Creating Python equivalent of MATLAB code using OMPC compiler
-
Visit http://ompc.juricap.com/download and download whatever of the archives cypher, tar.gz or tar.bz2 file
OR
You can also download by clicking on the links given below.
i. gip - https://www.bitbucket.org/juricap/ompc/get/tip.zip
ii. gz - https://www.bitbucket.org/juricap/ompc/go/tip.gz
iii. bz2 - https://www.bitbucket.org/juricap/ompc/go/tip.bz2
-
Suppose we downloaded zip, it will take the name juricap-ompc-96c520b01abc.zippo, double click on it to extract then you will get new directory named juricap-ompc-96c520b01abc.
-
Now, rename juricap-ompc-96c520b01abc directory to any proper name, suppose we renamed it to matlab-ompc-trial. Navigate inside the matlab-ompc-trial directoy from control final.
MacBook-Pro-2:matlab-ompc-trial admin$ cd ~/Downloads/ MacBook-Pro-2:Downloads admin$ MacBook-Pro-ii:Downloads admin$ mv juricap-ompc-96c520b01abc matlab-ompc-trail MacBook-Pro-2:Downloads admin$ MacBook-Pro-ii:Downloads admin$ cd matlab-ompc-trail/ MacBook-Pro-ii:matlab-ompc-trail admin$
-
You volition be able to see the following contents inside this directory.
MacBook-Pro-2:matlab-ompc-trial admin$ ls LICENSE examples ompc ompceg sandbox test.py README licenses ompc.cfg ompclib setup.py MacBook-Pro-two:matlab-ompc-trial admin$
-
Place the matlab-ompc-trial directory in a proper place in your arrangement. Suppose nosotros moved/copied/placed matlab-ompc-trial on ~/Desktop from Terminal. You tin employ GUI likewise.
MacBook-Pro-2:Downloads admin$ mv matlab-ompc-trial/ ~/Desktop/ MacBook-Pro-2:Downloads admin$ MacBook-Pro-ii:Downloads admin$ cd ~/Desktop/ MacBook-Pro-2:Desktop admin$ MacBook-Pro-2:Desktop admin$ cd matlab-ompc-trial/ MacBook-Pro-2:matlab-ompc-trial admin$
-
Create a file named box_volume.m and paste the following shadowed code.
box_volume.m
% ********************************************** % created on : vi January 2018 % aim of lawmaking : To calculate book of a square % coded by : Rishikesh Agrawani % ********************************************** % Function that calculates base expanse of a box office area = box_area(length, width) surface area = length * width; end % Function that alculates volume of a box, it calls box_area() to get base area function volume = box_volume(length, width, summit) volume = box_area(length, width) * meridian terminate
-
Now, create python file named box_volume_test.py in the aforementioned directory and paste the following lawmaking
box_volume_test.py
import ompc addpath('.') import box_volume v = box_volume(1, 2, 5); v1 = box_volume(1, 2, 3) v2 = box_volume(12, 5, 10)
-
Finally run the python file from terminal using python box_volume_test.py. You lot will be able to meet the post-obit on terminal.
MacBook-Pro-2:matlab-ompc-trial admin$ python box_volume_test.py /Users/admin/Desktop/matlab-ompc-trial/ompc/byteplay.py:43: UserWarning: byteplay supports only Python versions ii.4 and 2.5 warnings.warn('byteplay supports but Python versions 2.4 and 2.5') An "end" without matching keyword! On line: 10! An "end" without matching keyword! On line: fifteen! Importing m-file: "/Users/admin/Desktop/matlab-ompc-trial/box_volume.m" ans = 10.0 ans = vi.0 ans = 600.0
cashwelllouns1959.blogspot.com
Source: https://gist.github.com/hygull/78f03c98a7dfeac9b4b0fbd9fa3b1d85
0 Response to "How to Upload Matlab Code Into Github"
Postar um comentário