Java calls MATLAB functions

Source: Internet
Author: User

How to visualize the results of the experiment in MATLAB, using the Java language to programmatically invoke the functions in MATLAB:

I installed the Matlab7.11.0 (r2010a) and Eclipse 4.2;

1) First set environment variables, run tomcat,eclipse and so on need to rely on the environment variable Java_home,path,classpath, specific settings can refer to here

In order for the. m function to be compiled into a jar package in MATLAB, you also need to add the following in Classpath:

%matlabinstallroot%\r2010a\toolbox\javabuilder\jar\javabuilder.jar (depending on the version of MATLAB)

2) Compile the Matlab m file into a jar package

Here we use Matlab's own example, in the path

%matlabinstallroot%\r2010a\toolbox\javabuilder\examples\plotexample

Below, here is the M file:

function Drawplot (x, y)  plot (x, y); percent use MATLAB function plot ()  


Enter Deploytool in the command window in MATLAB to bring up the deployment tool Deploymenttool. Create a new project, enter the project name DEMO.PRJ, select the path, and select Target as the Java package.

Our new project will appear on the right side of MATLAB.

Simply drag and drop the M file you just wrote, rename the class name plotter, and click Build to compile:

After clicking Compile (the process is a bit long ~), see build finished. You will see the demo folder under the path you just set.

3) Calling Matlab-generated classes in Java engineering

Create a new project Trymatlabplot, and right-click in the build path to reference the related package

%matlabinstallroot%\r2010b\toolbox\javabuilder\jar\jarbuilder.jar

And the Plotdemo\distrib\plotdemo.jar just generated.

Problems encountered during the

"1" with Matlab drawing (an industrial project), and then the use of Java calls, jar package or something has been finished, but the program does not error, but the image is not displayed. Similar post questions

Answer: The Java call may not show the diagram because of a JDK version issue
jdk1.7 doesn't seem to show. You can use the jdk1.6.

"2" error after using jdk1.6, similar post:

Exception in thread ' main ' This component is trying to use is:7.13.

Answer: Copy a mclmcrrt713.dll and put it under the c:/windows/system32.

MATLAB compiler™ can compile your MATLAB® program into a standalone application, or a shared library that can be integrated with other common programming languages. By installing the MATLAB Compiler Runtime, users without MATLAB can also use MATLAB Compiler to create applications and libraries without paying royalties. You can either package the MATLAB Compiler Runtime with your application or let your users download "MCR" during the installation process.

Today, some students encountered this problem, the internet looked like because of your MATLAB running Java Virtual machine and your program's Java Virtual machine, a 64-bit, a 32-bit, or a different version caused. Matlab input Version-java Look at the Java version, and then if it is 64 bit, go to the next installation. I'm using eclipse to provide you with a way to modify eclipse, go to your eclipse point window=>preferences=>installed jres=>add, add the new installation in, and then go to your project right button = Properties=>java build path=>libraries deleted the previous JRE, then click Add  librariy=>jre system Library=>alternate JRE, Choose the Jre,finishing,ok you just installed, complete, run, young, good luck "reference"

The Java Virtual Machine version of Matlab2010ra is Jdk1.6.0_12

Jdk1.6.0_12 's

Java calls MATLAB functions

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.