MyEclipse calling the Matlab wrapper function

Source: Internet
Author: User
Tags mul

Part of this article refers to http://www.360doc.com/content/15/1103/16/1180274_510463048.shtml

First, check the Java environment

For computers that already have a Java environment installed, first determine whether the installed environment is compatible with the current MATLAB builder for Java version, which is the r2014a version of Matlab used in this article.

In CMD.EXE, type: java-version

If the information in the diagram appears, the Java environment is already installed and you can see its version

  

Further input javac-version in cmd

You can get the version information explicitly

  

Now get the Java environment information, and then to see if in MATLAB is compatible with this version, in MATLAB (using the version is 2014a) command Window input Version-java, get this result

  

You can see that the two are compatible, if the two version number is different but the difference is very close.

Second, write Matlab function and generate. jar Package

Here you write two functions operation (A, B), and Measuredim (c) two functions, which return the arithmetic of a, B, and the dimensions of the one-dimensional array C, respectively.

 Operation.m

function [Sum,sub,mul,div] = operation (A, B)
sum = a+b;
Sub = a-B;
Mul = a*b;
div = A/b;
End

  Measuredim.m

Function Dim = Measuredim (A)
Dim = Length (a);

Type Deploytool in the command line arguments

Pop up the following screen and select "Application Compiler"

  

Further popup the following interface

Select the type of application you want to package at 1, select "Java Packages", add the interface functions in the class at 2, select the MCR plug-in at 3 (whichever you choose, in fact you will first look at whether the computer has an MCR, do not use the corresponding action), at 4 fill in the project name, Continue looking down at this page

  

Modify the name of the class at 5 and add the other functions required to run the class at 6, preferably by adding the functions of MATLAB called in the M file.

Now it's almost all set.

Click on the "Setting" button on the side of the page to set the file location and click on the package to generate the corresponding file

In the packaging process, there is an interface with the following warning

Click Log file to see what the problem is, and notice that a warning appears in the document

Look at the Internet other netizens, this warning harmless, indeed, later in the MyEclipse called the generated program, and there is no problem. ( but still want to know how to fundamentally remove these warnings, if there is a passing to know what to do with the great God seeking guidance! )

Iii. calling programs in MyEclipse

1, first in the project to import the MATLAB generated jar file, and found in the MATLAB installation folder Toolbox-->javabuilder-->jar-->javabuilder.jar, also import it into the project.

Write the test code as follows, Myoperation is a packaged class, operation and Measuredim are included two functions

  

   

Operation Result:

Operation Result: 3
Operation Result: 1
Operation Result: 2
Operation Result: 0.5000
Number of dimensions: 3

2. Summary

When generating function arguments for MATLAB, you need to convert the data to Mwnumericarray type for MATLAB to recognize

Further assigning more than one parameter to an array of objects, or directly entering parameters, is either operationre = Aopera.operation (4, MA,MB) or operationre = Aopera.operation (4 , Inpara) are all possible.

The return value type of the MATLAB generating function is object[], the initialization of the process object[].

  

  

  

  

  

  

  

MyEclipse calling the Matlab wrapper function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.