In many ways we use the powerful mathematical computing power of MATLAB, while the Java language is the most used programming language today. Now Android is also implemented using the Java language.
I've done a few steps on how to do mixed programming.
The first step: Of course, the installation of the MATLAB program and JDK, I use the MATLAB version is r2013a, JDK is version 1.7, while using the Eclipse development tools as a Java development tool.
Step Two: Write a function in MATLAB, as follows:
Step three: Use the Deploytool command in MATLAB to package. As follows:
Fourth step: The following interface will appear, we need to add a good name, the most important is the type to choose the Java Package option.
Fifth step: In Matlab, the right Pop-up dialog box, note that you need to add a class, that is, click Add Classes, enter the name of the class, this name is packaged in the package name. Named Test.
Sixth step: After adding the class, we need to add a file for this class, add files, I just wrote a function, can actually add a lot of functions, select our Write the addition function file operation.m, select, open.
Seventh step: After the sixth step is completed, the following interface appears.
Eighth step: To continue the step is to have a build button, in fact, is the packaging button, we click on the long package it
Nineth step: Just start packing
Tenth step: When the build finished, it means that we have packaged successfully.
11th Step: To create a Java project in Eclipse, the key step is to import our successfully packaged jar package, which is in the SRC folder under the Project name folder under the Created MATLAB project folder, which is the Test.jar file that was just named Note that we also need another jar package, which is the Jarbuild.jar in MATLAB, the general path is E:\Program Files\matlab\r2013a\toolbox\javabuilder \jar (MATLAB parsing jar package file)
The 12th step: in Java can be arbitrarily call our class, the result is also returned correctly;
Where the return value of the operation is called in Java, the Object a[] = test.operation (1,a,b) is called in Java, and 1 means that there are 1 return values stored in a[0].
At this point a relatively simple hybrid programming program has ended. Feel good to order a praise, if you want to communicate, you can scan the following QR code for communication:
A tutorial on mixed MATLAB and Java programming