How to embed Matlab code in Java (for Android Studio)?

4 Ansichten (letzte 30 Tage)
Ismael Raqi Picardo
Ismael Raqi Picardo am 18 Feb. 2023
Beantwortet: Shubh Dhyani am 1 Mär. 2023
Hi, I have the following problem, I have a project built in Android Studio (using Java as language) for mobile devices, and I have also a set of functions in Matlab that receive as input an image and after a treatment, give an output.
In what way (the simplest possible) could I embed the Matlab code to be called from my code in Android Studio?
Either encapsulating my Matlab functions in some package with some dependency, transforming the code into another one and embedding it directly or any way that is possible.
Thank you very much in advance!

Antworten (1)

Shubh Dhyani
Shubh Dhyani am 1 Mär. 2023
Hi Ismael,
I understand that you want to know the simplest way to embed your MATLAB code in your code in Android studio.
One way to call your MATLAB functions from Android Studio is to use the MATLAB Compiler SDK. The MATLAB Compiler SDK allows you to compile your MATLAB code into a standalone executable or shared library that can be called from Java or other programming languages. Here are the basic steps:
1. Install the MATLAB Compiler SDK on your MATLAB installation. This requires a separate license from MATLAB itself.
2. Write a MATLAB script or function that takes an image as input and produces an output. Test that the script or function works correctly in MATLAB.
3. Compile the script or function using the MATLAB Compiler SDK. This will create a shared library or executable that can be called from Java.
4. Import the compiled shared library or executable into your Android Studio project as a dependency.
5. Write Java code in your Android Studio project that calls the compiled MATLAB function or script. Pass the image as input and get the output as a result.
Note that the MATLAB Compiler SDK may not be the only solution to your problem, but it is a common and well-supported one. There may be other libraries or tools that allow you to call MATLAB code from Java, such as the MATLAB Engine API for Java, but these may require more setup and configuration.

Kategorien

Mehr zu MATLAB Compiler SDK finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by