The other day, a user told me: That would be cool if we could program apps for smartphones using Simulink.
Guess what my answer was: Of course you can!
Simulink Support Packages for Apple iOS and Android
Since he works mostly in the Apple ecosystem and I don't, I asked my colleague Mariano Lizarraga Fernandez to be guest blogger this week and describes his first experience trying to build an app for his iPhone.
Before you get started, make sure you have the following:
- An Apple computer running OS X Yosemite or El Capitan with MATLAB and Simulink installed.
- Xcode 7.x.
- A free Apple Developer Account.
- The Simulink Support Package for Apple iOS.
- An iOS device running iOS 8.x or 9.x.
Make sure that when you install the Support Package you completely follow the setup instructions including obtaining a certificate for signing the application. You need to make sure, in your Xcode preferences, that your certificate is valid and that the identifier matches that of your application. In the following picture, CBDemo is the name of the Simulink model:
For your first model, as suggested in the Getting Started documentation page, an easy test is to acquire the camera video, and display it on the screen. You can directly access this demo by executing iosGettingStartedExample in MATLAB.
Before running this model, open the model's Configuration Parameters, and in the Hardware Implementation section make sure the Hardware Board is configured for Apple iOS Devices and that your iOS Device is shown in the Target Hardware Resources:
Now to the Fun Part ...
The model as-shipped loads a video from your filesystem and performs identification of stop and yield traffic signs. To adapt it for the iOS target, we only need to replace source and sink. Instead of just replacing the blocks, we decided to use Variants Subsystems to switch between a simulation-only version, and a deployable version.
For the source, we use the iOS camera source block. Since this source only produces 8-bit unsigned integers, we need to modify: (1) How the From Multimedia File block produces the output so it too results in 8-bit unsigned integers; and (2) Convert the 8-bit frame to single precsision floating point one using the im2single function.
Similarly, for the sink variant, since the iOS Video Display block only accepts 8-bit unsigned integers, we convert the processed image from single precision floating point to 8-bit unsigned integers using the im2uint8 function
Here is what this looks like in action on an iPad mini:
Now it's your turn
What kind of app will you create for your iPhone or iPad? Noise cancelling headphone? Driving assistant for blind people?
If you create a cool app, submit it to MATLAB Central File Exchange and let us know in a comment below.