How to plot a graph of xy values on android app interface when values are generated from a Simulink model?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 8 Oct 2020
Edited: MathWorks Support Team
on 4 Feb 2025
For the user interface in Android device, we want to plot a graph of 'x' and 'y' values where 'x' is not time on the android app interface. We can see that there is a block in Simulink called ‘x-y plot’ we can use for our purpose, but this block is currently not supported (as of MATLAB R2020a) for Android. We can have scopes on the screen but can not change the x-axis parameter from time to a customizable parameter. How to plot 'xy' values generated from a Simulink model, onto an Android app?
Accepted Answer
MathWorks Support Team
on 24 Jan 2025
Edited: MathWorks Support Team
on 4 Feb 2025
Following are two possible workarounds:
1. 'Array plot' block from the DSP toolbox. Android supports the Array Plot block for deployment. Array plot block does not have time as the x-axis. You can use a customizable parameter instead.
2. Once the Simulink model-generated app code is exported to Android Studio, you can modify Java/XML code (in Android Studio) and run it on the device (from Android Studio). It will run the Simulink generated algorithm under the hood. 'To App' Block and 'From App' Block can be used to access Simulink model data to and from Android App's main activity's Java function. You need to mention the function name (the one you will write in Java after exporting to Android Studio) in the block mask. Simulink model-generated C code then calls these Java functions to receive/send data. There are examples that use this workflow to integrate custom Java code with a 3rd party library along with Simulink model-generated code. To access these examples, execute the following commands in MATLAB R2020a:
For the "Set Position of Bebop Drone on Gazebo Simulator from Android Device Using ROS" example:
>> web(fullfile(docroot, 'supportpkg/android/ref/set-position-of-bebop-drone-on-gazebo-simulator-from-android-device-using-ros.html'))
For the "Visualize Sensor Data from Android Device in RViz" example:
>> web(fullfile(docroot, 'supportpkg/android/ref/visualize-sensor-data-from-an-android-device-in-rviz-example.html'))
You can customize the required UI in Android Studio and implement an XY plot-like chart in Android Studio that receives data from the 'To App' block. Currently, Android code generation uses a 3rd party chart library for 'scope' and 'array plot' block in Android. That library has other charts also (like line chart) which can be used to implement a custom view. If a scope or array plot block is in the model, that library will be integrated inside the generated Android project. The library link is: https://github.com/PhilJay/MPAndroidChart. So, if there are an array plot and 'To App' blocks in the model, then the other charts can be directly integrated into the code.
Please follow the link below to search for the required information regarding the current release:
0 Comments
More Answers (0)
See Also
Categories
Find more on Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!