Using Ecilpse (Java) to invoke MATLAB code

Source: Internet
Author: User

1 Installing the Java environment:

Http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download the latest version of the JDK and install it, Cloudsim needs to run in jdk1.6 or later.

Take jdk1.6.0_24 as an example, the default installation directory is C:\Program files\java\jdk1.6.0_24.

Set Environment variables:

New system variable java_home, the variable value is set to the JDK installation directory, that is C:\Program files\java\jdk1.6.0_24;

Add path%java_home%\bin in path ; %java_home%\bin\javac;

Add path %java_home%\lib\dt.jarin ClassPath ; %java_home%\lib\tools.jar

2 matlab code compiled into a Java package:

Enter a command in MATLAB to see if you can access the Java configuration:

>> getenv Jave_home

The configuration will return the JDK path that you configured, and if MATLAB is already open during the configuration path, restart.

Create a new function file funtest.m(must be a function file: New file->function! There can be only functions in the file, no independent scripts)

Enter the following:

 out] = Funtest (A, b)    out= a + b; end 

In the Command Window , enter:

>> Deploytool

Find the folder corresponding to the project name "Distrib\funtest.jar" This file is the generated Java package. (funtest path is best not too deep!) Otherwise you will get an error. )

3 JRE with 64/32 bit MATLAB+64/32 bit:

(Remember to keep it consistent.) Otherwise, the error will be invoked, or the same 32-bit is used, as in the case of 64 bits)

32/64-bit JRE Download: http://www.java.com/zh_CN/download/manual.jsp

Install after download.

4 Use Ecilpse to invoke the Java package generated by MATLAB.

Find the MATLAB installation path, I am here D:\Program Files\matlab\r2013a\toolbox\compiler\deploy\win64 below the MCRInstaller.exe file . For installation.

Create a new Java project and insert the following code:

Package Test;import Com.mathworks.toolbox.javabuilder.*; import funtest.*; Public classMyfuntest {/** * @param args * @throws mwexception*/     Public Static voidMain (string[] args) throws Mwexception {//TODO auto-generated Method StubCfuntest cp=Newcfuntest (); Object bn[]=NULL; Mwnumericarray a=NULL; Mwnumericarray b=NULL; A=NewMwnumericarray (Double.valueof (5), mwclassid.double); b=NewMwnumericarray (Double.valueof (5), mwclassid.double); Bn=cp.funtest (1, A, b); System. out. println (bn[0]); }}

Post-run output results: 10

Call succeeded!

Cloudsim Installation and configuration

Download Cloudsim from http://www.cloudbus.org/cloudsim/, take CloudSim2.1.1 for example. Unzip it to a disk, such as C:\cloudsim-2.1.1.

Set Environment variables:

Add path C:\cloudsim-2.1.1\jars\cloudsim-2.1.1.jar to ClassPath ; C:\cloudsim-2.1.1\jars\cloudsim-examples-2.1.1.jar

In this case, the MATLAB code can be called in the Cloudsim in the same way.

Using Ecilpse (Java) to invoke MATLAB code

Related Article

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.