Create your first Android app custom made with MATLAB/simulink

Recently, I accidentally discovered that MATLAB/simulink is very powerful. You do not need to know additional knowledge of android, Java JNI, C/C++, etc., you can directly build your model in simulink and then convert it into your own app. The functions and controls are completely up to you. come to grasp! (Apple mobile phone users can also, the following is just an example of Android to illustrate)

1. Simple Android app DEMO

Let's take a screenshot of my own android app first:



The above is a simple color threshold segmentation image app I built. In the first picture, the small squares on the wall were originally a little green. After adjusting the threshold, I "painted white" the green grid as a mask~ The real-time performance is not bad. Note that it is not pure MATLAB code to run on Android! Instead, it is C/C++ code automatically generated by simulink. You almost do not need programming in the whole process, you only need to understand the basic simulink module operation and a small amount of MATLAB knowledge.


2. Construction process

1. First, make sure that the MATLAB version you installed is at least 2014b and later. The MATLAB toolbox needs to depend on simulink, simulink coder, etc. If you don't know it, all are installed by default. This blog uses the 2017a version, and 2017b supports Bluetooth modules.

2. Open your MATLAB, find add ones in the toolbar to get additional tools, then search for "simulink support package", there will be many supported installation packages, find the red box in the figure below and download and install.




3. After the above is installed, open the simulink library, find the simulink support packages for android devices, and you will see a lot of android modules, as shown in the following figure.



Then you can create a new simulink model and start to formally build your model. The module parameters are set according to your own requirements. My model is roughly like this. If you don't want to build, you can download it directly from here .



ok! After the setup is complete, connect your Android phone to your computer through a USB cable. The computer and the phone share the same wifi. You need to make simple settings in the Android phone, usually in "Settings" --> "More" --> "Development" User Options"-->"USB Debugging", so that "USB Debugging" is selected, as shown below, find a similar corresponding location on your Android phone.


4. Open the model built above, and then find "Simuluation" -> "Model configuration paremeters" in the menu bar, and then select the hardware platform as shown in the red box below.


OK, ok, then you can directly install the simulink model to your Android device.

3. Generate Android APP

In the simulink model window above, find the following icons of many arrows, click and wait for a while, you can generate your own customized app, as shown below:


Finally, if it is successful, a code generation report will pop up, which is full of C/C++, which is readable and portable~



Of course, you don't need to worry about the above code, just look at it. You can also integrate the above code into android studio in the future. You have time to study this. The time is limited and the writing is relatively rough. Everything is going well~ If netizens follow There is a problem with the download and installation of the above steps, which can basically be solved after several attempts. Now you can go back to your phone to see the perfect app running~

In order to facilitate the download of the installation package, a link is given after downloading (Matlab2017b package): link: https://pan.baidu.com/s/17m90c-_4uIX5H1HgW22Uyg Password: iyrn

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325592738&siteId=291194637