I have used the JavaBuilder that comes with Matlab so that I can use Matlab functions from my JAVA program. In order to do that, I need to have the Matlab Compiler installed. Is there a way to do use Matlab from JAVA, but without the need to have the Matlab Compiler? I mean, can Matlab create the JAVA version of the matlab function (translate from matlab to JAVA)?
Thank you
If you have Matlab (but you don't have builderJA) then you can use matlabcontrol for using matlab functions in java.(There might be other alternatives too, but I don't know)
If you don't have Matlab at all then you can "create the java version of the matlab function" in some other computer having Matlab and builderJA installed, and use the jar files in your own computer. You only need to have MCR (Matlab Compiler Runtime- Its FREE) installed on your computer.
Strickly answering your question:
Is there a way to do use Matlab from JAVA, but without the need to
have the Matlab Compiler?
The answer is:
Yes, you can use it. Using matlabcontrol (A java API to interact with Matlab).
matlabcontrol is a Java API which will allow you to call MATLAB from Java. It does not make use of any compiler.
You can either call MATLAB from within MATLAB or from outside MATLAB in which case an instance of MATLAB is launched and connected to. It allows for invoking eval and feval in MATLAB and returning the results to MATLAB. The walkthrough explains with examples how to do this.
Related
I am creating a Windows program that so far has a .bat file calling a .pyw file, and I need functions from Java and C++. How can I do this?(I don't mind creating a new batch or python file, and I already have the header file for the C++ section and a .jar file for my java components. (For Java I use Eclipse Java Mars, and it's Java 8u101)) Thanks!!!
This is rather simple for C++: you have to compile a library with the function, import it in Python and... call it! Python has a powerful ctypes module in the standard library to handle this kind of tasks.
Here is an example of loading print() function from hypothetical libc.dll.
from ctypes import *
libc = cdll.LoadLibrary("libc.dll")
>>> print(libc.time(None))
1150640792
Calling Java from Python is covered here: How to call a java function from python/numpy?
You can load C++ function and execute it from Python like BasicWolf explained in his answer. For Java, Jython might be a good approach. But then there's a problem - you will need to be dependent on Jython which is not up to date with the latest versions of Python. You will face compatibility issues with different libraries too.
I would recommend compiling your C++ and Java functions to create individual binaries out of them. Then execute these binaries from within Python, passing the arguments as command line parameters. This way you can keep using CPython. You can interoperate with programs written in any language.
I have an algorithm and some other code which is in MATLAB and I want to use it in my Android application.
How can I do this?
Can I make a jar file from MATLAB for use with Android?
I have to do something else?
If you have an additional product, MATLAB Builder JA for Java, you can produce a .jar file from your MATLAB code.
However, the .jar file requires the MATLAB Compiler Runtime (a freely redistributable component that you get with MATLAB Compiler and MATLAB Builder products) to be present. The MCR has a much larger footprint than is suitable for the typical Android device (it's like a copy of MATLAB itself, without the user interface).
You could think about either
Running your MATLAB .jar file remotely on a server, and having your Android application connect to it, or
Instead of using MATLAB Compiler and Builder products, use MATLAB Coder, which will convert a subset of the MATLAB language directly into C code. This C code doesn't require the MCR, and could be compiled to run directly on Android. Make sure your MATLAB algorithm falls within, or can be expressed in, the appropriate subset of the MATLAB language.
Edit: As of R2015a, functionality from MATLAB Builder JA for Java has been replaced by a new product, MATLAB Compiler SDK.
I am the developer of Addi. http://addi.googlecode.com Addi is quickly becoming a full port of Octave (which is an open source tool that uses Matlab syntax). Addi is going to have intents for other applications to use it as their math engines or plotting engines. So, if you can run your code on Octave, then very soon you will be able to run it on Android.
Our only option is to get C++ code from M code using MATLAB Coder toolbox, that generates standalone C and C++ code from MATLABĀ® code. It supports only some subset of all Matlab functions, therefore might be not suitable for your needs.
Having C code you can compile it using NDK. MATLAB Compiler is not an option here.
A new feature in Matlab 2014a:
http://www.mathworks.com/help/simulink/samsung-galaxy-android-devices.html
You can now directly install (limited set of) models to Samsung Android devices, and this should work actually on any Android device.
You can convert matlab code into python and then use the python code in the android .There are many tools to do this conversion. Python goes well with android than matlab.
You have 2 options,
Create a JAR and include in your Java Application and start using it. (I have not tested this by creating a JAR outside Eclipse)
You can code the same thing in C and use Android NDK to process it. (This will be faster and safer way)
I have created a Java gui and want to execute MATLAB (.m) functions to execute on click events of jButtons of my Java GUI. I searched on internet and found a way to do this by MATLAB Builder.
Is there any other way than MATLAB Builder which can be used to perform the same?
Yes, you can use JMI or JMatLink to interface with MATLAB from Java. Or, if you're more adventurous, you can roll your own JNI or JNA library to interface directly with MATLAB's C API.
matlabcontrol is a Java API which will allow you to call MATLAB from Java. You can either call MATLAB from within MATLAB or from outside MATLAB in which case an instance of MATLAB is launched and connected to. It allows for invoking eval and feval in MATLAB and returning the results to MATLAB. The walkthrough explains with examples how to do this.
Did anyone made a coupling between Java and Matlab and can advise how this can be done best? Is there eg a framework that I should not miss to look at?
I want to write a java program that hands parameters to a matlab function and gets the result (and pictures created in matlab based on iterations) back.
Further these results shall be displayed on a website, so Java EE JSF will be my choice.
How can this coupling be done best?
You could try JAMAL (JAva MAtlab Linking): http://jamal.khadkevich.org/about.html
Yes, the Mathworks have made a coupling between Java and Matlab and can advise how this can be done best. You might start your reading at this page.
matlabcontrol is a Java API which will allow you to call MATLAB from Java. You can either call MATLAB from within MATLAB or from outside MATLAB in which case an instance of MATLAB is launched and connected to. It allows for invoking eval and feval in MATLAB and returning the results to MATLAB. The walkthrough explains with examples how to do this. The walkthrough uses built-in MATLAB functions and commands, but you can use it with your own .m files because using matlabcontrol is just like interacting with MATLAB's Command Window.
I'm writing an application which does image processing using matlab and later displays the result using Java's Interface. Due to certain reasons I've to use both Java and Matlab.
How can I use the matlab function in java ?? How to create and access the interface.
matlabcontrol is a Java API which will allow you to call your image processing functions or scripts and return the results to Java. To get started, take a look at the walkthrough.
MATLAB Builder JA is one option to use MATLAB code in Java. This is a non free toolbox for creating a jar file from MATLAB code in order to be imported to Java. Take care of the restrictions concerning jar file creation.
Using Java classes inside MATLAB is much easier, as you can instantiate Java classes in MATLAB code. Undocumented Matlab is one valuable resource for Java integration in MATLAB.
Check Using Sun Java Classes in MATLAB Software for the official information provided by The MathWorks.
A quick google brought up this http://j-integra.intrinsyc.com/support/com/doc/other_examples/Matlab.htm
Alternatively, can you execute your matlab function from the command line? If so you can use
Runtime.getRuntime().exec("your matlab function")
As of R2016b you can use official MATLAB Engine API for Java, which seems to allow same functionality as matlabcontrol.