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.
2 CommentsOldest to Newest
Amazing you app!
I am trying to acquire Iphone sensor data with simulink but I am not able to set up the support package. I get errors when the simulink example test tries to run at the last step of the support package installer. I think they are some problem of compatibility between Mac OS, Iphone IOS, Xcode and Matlab releases. Do you remember which release of each did you have for the video?
Thank you in advance,
For this particular model we used a MacBook with macOS El Capitan running R2016a with Xcode 7.3 and an iPad mini with iOS 9.1.
However, these are the requirements for the newest release:
Hardware: An iOS device with iOS version 9.x or higher. Tested on iOS 9.1 to 10.1
Software Xcode IDE 7.x and above. Tested with Xcode 7.0 and 8.1
You can see the complete list of requirements for the latest release of the Support Package here:
I Hope this helps. Let us know in the comments what you build!