17

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?
IKavanagh
  • 6,089
  • 11
  • 42
  • 47
Azhar
  • 20,500
  • 38
  • 146
  • 211
  • 1
    You can include jar in your android project. For this go to project property, under java builder open libraries tab. You can add your jar file from here – Jaiprakash Soni Mar 12 '12 at 07:06
  • 3
    I know, how to include a jar file .. I am asking how to make a jar from Matlab or if not jar then what to do . – Azhar Mar 12 '12 at 07:20

6 Answers6

15

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

  1. Running your MATLAB .jar file remotely on a server, and having your Android application connect to it, or
  2. 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.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
4

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.

corbin
  • 1,446
  • 2
  • 27
  • 40
3

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.

Alexander Kosenkov
  • 1,597
  • 1
  • 10
  • 21
3

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.

student1
  • 860
  • 3
  • 11
  • 22
0

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.

Community
  • 1
  • 1
user93
  • 1,866
  • 5
  • 26
  • 45
  • This is assuming that the OP isn't using any of the specialized toolboxes. Using just native MATLAB syntax won't pose as a problem, if he/she were to use things like the image processing toolbox, or signal processing toolbox, this conversion would not be possible. – rayryeng Nov 16 '14 at 21:25
-1

You have 2 options,

  1. Create a JAR and include in your Java Application and start using it. (I have not tested this by creating a JAR outside Eclipse)

  2. You can code the same thing in C and use Android NDK to process it. (This will be faster and safer way)

Vinay
  • 2,395
  • 3
  • 30
  • 35