{"id":2287,"date":"2013-06-18T07:59:02","date_gmt":"2013-06-18T12:59:02","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=2287"},"modified":"2013-06-18T07:59:02","modified_gmt":"2013-06-18T12:59:02","slug":"the-easiest-way-to-import-signals-into-your-model","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2013\/06\/18\/the-easiest-way-to-import-signals-into-your-model\/","title":{"rendered":"The Easiest Way to Import Signals Into Your Model"},"content":{"rendered":"<p>A benefit of Model-Based Design is using the same model to accomplish several tasks: tuning, testing, debugging, combining component models into larger system models, etc. Ideally, you should not have to modify your model to accomplish all of these tasks.<\/p>\r\n\r\n<p>In Simulink, there are many <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/signal-loading-techniques.html\">techniques for importing signals into a model<\/a>.  With that in mind, the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/load-data-to-root-level-input-ports-1.html\">root-level Input Ports<\/a> are the most convenient approach for importing data and maintaining model flexibility.  The root-level input port allows you to test your model with signals from the workspace and use your model as referenced model in a larger context without any modification.<\/p>\r\n\r\n<p><strong>Importing Data to Root-Level Input Ports<\/strong><\/p>\r\n\r\n<p>When you have Inport blocks at the root-level of your model, you can go to the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/gui\/data-import-export-pane.html\">Data Import\/Export section<\/a> of the model Configuration and specify which data should be used.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/specifyingInputsignals.png\" alt=\"Specifying Input signals in a Simulink model\" \/><\/p>\r\n\r\n<p>The challenge here is that the <strong>Input:<\/strong> field accepts so many different syntaxes that it is difficult to remember what to type here. Root inputs have been part of Simulink since version 1.0.  As Simulink evolved, the root Input Port evolved to accept all the new data types and signal specifications that were added to Simulink.  To ensure backward compatibility, the <strong>Input:<\/strong> field remained as free text.<\/p>\r\n\r\n<p>Here is a screen capture from the documentation listing the different forms of input data supported. Of course, the syntax for each of them is different.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/formsOfInput.png\" alt=\"Multiple ways of importing signals through root-level inport blocks\" \/><\/p>\r\n\r\n<p><strong>The Root Inport Mapping dialog<\/strong><\/p>\r\n\r\n<p>In R2012b, a new dialog was added to help filling the <strong>Input:<\/strong> text field. To launch it, click on the <strong>Edit Input<\/strong> button.\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/EditInput.png\" alt=\"Launching the Root Inport Mapping dialog\" \/><\/p>\r\n\r\n<p>For example, let's say I have a model with two Inport blocks named <strong>u1<\/strong> and <strong>u2<\/strong>. I can create a MAT-file containing 2 signals <tt>u1<\/tt> and <tt>u2<\/tt> using this example code:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/createMATFile.png\" alt=\"Creating a MAT-file containing two signals\" \/><\/p>\r\n\r\n<p>I click the <strong>Edit Signal<\/strong> button, select the MAT-file, select the <strong>Block Name<\/strong> option and click the <strong>Map Signals<\/strong> button. The dialog will verify that the data in the MAT-file is compatible with the model and show you the result:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/MappingTool.png\" alt=\"The Root Inport Mapping Dialog\" \/><\/p>\r\n\r\n<p>If the mapping is successful, you can click apply and the text in the <strong>Input:<\/strong> field will be updated:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/mappingResult.png\" alt=\"Input data specified using the Root Inport Mapping Dialog\" \/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>This example is very simple, but for for more complex cases the Root Inport Mapping dialog is very useful. Did you have a chance to try it? Was it useful? Let us know by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=2287&#comment\">comment here<\/a>.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/mappingResult.png\" onError=\"this.style.display ='none';\" \/><\/div><p>A benefit of Model-Based Design is using the same model to accomplish several tasks: tuning, testing, debugging, combining component models into larger system models, etc. Ideally, you should not... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2013\/06\/18\/the-easiest-way-to-import-signals-into-your-model\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,11,16],"tags":[204],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2287"}],"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=2287"}],"version-history":[{"count":25,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2287\/revisions"}],"predecessor-version":[{"id":2353,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2287\/revisions\/2353"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=2287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=2287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=2287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}