Guy on Simulink

Simulink & Model-Based Design

Creating iPhone and iPad Apps with Simulink

Posted by Guy Rouleau,

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

Yes, you heard it right. If you have a Simulink license, you can download the Simulink Support Package for Apple iOS, or if your prefer the Simulink® Support Package for Android™.

Simulink Apple iOS library

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.

Getting Started

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:

Xcode Configuration

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:

Model Configuration for iPad target

Now to the Fun Part ...

To give you an idea of what kind of app it is possible to create, we decided to start with an example from the Computer Vision system Toolbox: Traffic Warning Sign Recognition

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.

Video source for Simulink Apple iOS library

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

Video Sink for Simulink Apple iOS library

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.

Add A Comment

What is 1 + 2?

Preview: hide