Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab callbacks from Java

Subject: Matlab callbacks from Java

From: Shawn Hershey

Date: 24 Nov, 2008 05:41:02

Message: 1 of 2

I am currently developing a library for Matlab users at my company. The functions in the library are such that I hope to write the code in Java or C++ rather than in M. I have written Java code that is called by Matlab in the past and find it to be a nice interface, but this time I require my library functions make calls back to Matlab (ideally via function handles). This seems to be possible using C or C++ Mex files, but I was hoping to code in Java, not C/C++. Google searches haven't yielded any obvious solution. Is it not actually possible to do something like the following:

1) Make a Java call from matlab
2) From the called Java function, make multiple Matlab calls (either using Matlab function handles, function names, or anything else).

If this is possible, great! If not, I'm assuming I can do what I want using C/C++ MEX files.

Thanks in advance for your insight.

Subject: Matlab callbacks from Java

From: Yair Altman

Date: 15 Feb, 2009 07:15:09

Message: 2 of 2

"Shawn Hershey" <shliabnt@gmail.com> wrote in message <ggdepe$2hu$1@fred.mathworks.com>...
> I am currently developing a library for Matlab users at my company. The functions in the library are such that I hope to write the code in Java or C++ rather than in M. I have written Java code that is called by Matlab in the past and find it to be a nice interface, but this time I require my library functions make calls back to Matlab (ideally via function handles). This seems to be possible using C or C++ Mex files, but I was hoping to code in Java, not C/C++. Google searches haven't yielded any obvious solution. Is it not actually possible to do something like the following:
>
> 1) Make a Java call from matlab
> 2) From the called Java function, make multiple Matlab calls (either using Matlab function handles, function names, or anything else).
>
> If this is possible, great! If not, I'm assuming I can do what I want using C/C++ MEX files.
>
> Thanks in advance for your insight.

What you require is JMI (Java-Matlab interface) - it's available but undocumented and discouraged by Matlab for reasons unknown. You can google JMI or search this forum for some references. Xtargets (http://www.xtargets.com/snippets/tag/jmi) and JMatLink (http://www.held-mueller.de/JMatLink/) are also good starting points. You can also explore the jmi.jar package which is bundled with Matlab (in the ...\Java\jar\ folder).

Yair Altman

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us