user3385015 user3385015 - 1 year ago 237
Java Question

Matlab to C to Android

I have a fully functional Android App (Java) that is missing an Algorithm. I coded this Algorithm in Matlab.

I read on another part of this site, that Matlab had the ability to convert Matlab code into C code (up to a certain extent).

My question:

  1. Is it possible to integrate this with my already functioning java

  2. Is the Android NDK for starting codes off from C/C++?

  3. Is there anyway for me to connect a initialized value from my code
    to the code in C?

Thank you.

Answer Source

The add-on product MATLAB Coder allows you to convert a subset of the MATLAB language into C code. You would need to ensure that your MATLAB algorithm falls within this subset, or recode it so that it does, in order to produce C code from it.

The supported subset changes (gets larger) each release, but a few big restrictions currently include:

  • No cell arrays edit some cell array support since R2015b
  • No object-oriented code edit some OO functionality is supported since R2012a
  • No anonymous or nested functions
  • No sparse matrices
  • No try \ catch

I have no experience developing for Android in Java, but I would expect that if you can call C in general, you'll be able to call the C code generated from MATLAB. If it's of interest to you, I know that MathWorks have a demo (I'm afraid I can't find it on the website, but you can contact them to find it) of generating C code that is deployed to an iPhone with an Objective C wrapper, and they may internally have an example of something similar for Android that they would be willing to share with you.

As an aside, another way for you to integrate a mobile application with MATLAB code might be to use one of the Builder products (MATLAB Builder for Java or MATLAB Builder for .NET) to deploy your MATLAB algorithm as a web service, and have your Android application call that. Depending on your application and the nature of the MATLAB portion, that may or may not be a better option.

EDIT: MathWorks are hosting a MATLAB Virtual Conference TODAY at which one of the presenters (Bill Chou, the product manager for MATLAB Coder) will be demonstrating how to deploy generated C code to iPhone. I would guess the process may be similar for Android, and you'll be able to ask him questions after the presentation. Go register now, you may be in time to catch him!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download