{"id":5434,"date":"2016-11-08T17:12:14","date_gmt":"2016-11-08T22:12:14","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=5434"},"modified":"2016-11-08T17:14:06","modified_gmt":"2016-11-08T22:14:06","slug":"creating-iphone-and-ipad-apps-with-simulink","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2016\/11\/08\/creating-iphone-and-ipad-apps-with-simulink\/","title":{"rendered":"Creating iPhone and iPad Apps with Simulink"},"content":{"rendered":"<p>The other day, a user told me: <em>That would be cool if we could program apps for smartphones using Simulink<\/em>.<\/p>\r\n\r\n<p>Guess what my answer was: <em>Of course you can!<\/em><\/p>\r\n\r\n<p><strong>Simulink Support Packages for Apple iOS and Android<\/strong><\/p>\r\n\r\n<p>Yes, you heard it right. If you have a Simulink license, you can download the <a href=\"https:\/\/www.mathworks.com\/hardware-support\/ios-device-simulink.html\">Simulink Support Package for Apple iOS<\/a>, or if your prefer the <a href=\"https:\/\/www.mathworks.com\/hardware-support\/android-programming-simulink.html\">Simulink\u00ae Support Package for Android\u2122<\/a>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q4\/iosgettingstartedexample_02.png\" alt=\"Simulink Apple iOS library\" \/><\/p>\r\n\r\n<p>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.<\/p>\r\n\r\n<p><strong>Getting Started<\/strong><\/p>\r\n\r\n<p>Before you get started, make sure you have the following:<\/p>\r\n\r\n<ul>\r\n\t<li>An Apple computer running OS X Yosemite or El Capitan with MATLAB and Simulink installed.<\/li>\r\n\t<li>Xcode 7.x.<\/li>\r\n\t<li>A free Apple Developer Account.<\/li>\r\n\t<li>The <a href=\"https:\/\/www.mathworks.com\/hardware-support\/ios-device-simulink.html\">Simulink Support Package for Apple iOS<\/a>.<\/li>\r\n\t<li>An iOS device running iOS 8.x or 9.x.<\/li>\r\n<\/ul>\r\n\r\n<p>Make sure that when you install the Support Package you completely follow the setup instructions <strong>including obtaining a certificate for signing the application<\/strong>. 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, <strong>CBDemo<\/strong> is the name of the Simulink model:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q4\/XcodeConfig.png\" alt=\"Xcode Configuration\" \/><\/p>\r\n\r\n<p>For your first model, as suggested in the <a href=\"https:\/\/www.mathworks.com\/help\/supportpkg\/appleios\/examples\/getting-started-with-apple-ios-devices.html\">Getting Started documentation page<\/a>, an easy test is to acquire the camera video, and display it on the screen. You can directly access this demo by executing <tt>iosGettingStartedExample<\/tt> in MATLAB.<\/p>\r\n\r\n<p>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:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q4\/iosConfigParams.png\" alt=\"Model Configuration for iPad target\" \/><\/p>\r\n\r\n<p><strong>Now to the Fun Part ...<\/strong><\/p>\r\n\r\n<p>To give you an idea of what kind of app it is possible to create, we decided to start with an example from the <a href=\"https:\/\/www.mathworks.com\/products\/computer-vision\/\">Computer Vision system Toolbox<\/a>: <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016a\/vision\/examples\/traffic-warning-sign-recognition.html (link no longer works)\">Traffic Warning Sign Recognition<\/a><\/p>\r\n\r\n<p>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 <a title=\"https:\/\/www.mathworks.com\/help\/simulink\/examples\/variant-subsystems.html (link no longer works)\">Variants Subsystems<\/a> to switch between a simulation-only version, and a deployable version.<\/p>\r\n\r\n<p>For the source, we use the <a href=\"https:\/\/www.mathworks.com\/help\/supportpkg\/appleios\/ref\/camera.html\">iOS camera source<\/a> block. Since this source only produces 8-bit unsigned integers, we need to modify: (1) How the <a href=\"https:\/\/www.mathworks.com\/help\/dsp\/ref\/frommultimediafile.html\">From Multimedia File<\/a> 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 <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/im2single.html\"><tt>im2single<\/tt><\/a> function.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q4\/iosSources.png\" alt=\"Video source for Simulink Apple iOS library\" \/><\/p>\r\n\r\n<p>Similarly, for the sink variant, since the <a href=\"https:\/\/www.mathworks.com\/help\/supportpkg\/appleios\/ref\/videodisplay.html\">iOS Video Display<\/a> block only accepts 8-bit unsigned integers, we convert the processed image from single precision floating point to 8-bit unsigned integers using the <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/im2uint8.html\"><tt>im2uint8<\/tt><\/a> function<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q4\/sinkVariant.png\" alt=\"Video Sink for Simulink Apple iOS library\" \/><\/p>\r\n\r\n<p>Here is what this looks like in action on an iPad mini:<\/p>\r\n\r\n<p><iframe loading=\"lazy\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/AMLdghppCn4?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><br><a href=\"https:\/\/youtu.be\/AMLdghppCn4\">https:\/\/youtu.be\/AMLdghppCn4<\/a><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>What kind of app will you create for your iPhone or iPad? Noise cancelling headphone? Driving assistant for blind people?<\/p>\r\n\r\n<p>If you create a cool app, submit it to <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\">MATLAB Central File Exchange<\/a> and let us know in a comment below.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q4\/sinkVariant.png\" onError=\"this.style.display ='none';\" \/><\/div><p>The other day, a user told me: That would be cool if we could program apps for smartphones using Simulink.\r\n\r\nGuess what my answer was: Of course you can!\r\n\r\nSimulink Support Packages for Apple iOS... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/11\/08\/creating-iphone-and-ipad-apps-with-simulink\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[71],"tags":[487,485,486],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5434"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=5434"}],"version-history":[{"count":16,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5434\/revisions"}],"predecessor-version":[{"id":6012,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5434\/revisions\/6012"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=5434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=5434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=5434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}