# Guy and Seth on Simulink

## The Easiest Way to Import Signals Into Your Model

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.

In Simulink, there are many techniques for importing signals into a model. With that in mind, the root-level Input Ports 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.

Importing Data to Root-Level Input Ports

When you have Inport blocks at the root-level of your model, you can go to the Data Import/Export section of the model Configuration and specify which data should be used.

The challenge here is that the Input: 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 Input: field remained as free text.

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.

The Root Inport Mapping dialog

In R2012b, a new dialog was added to help filling the Input: text field. To launch it, click on the Edit Input button.

For example, let's say I have a model with two Inport blocks named u1 and u2. I can create a MAT-file containing 2 signals u1 and u2 using this example code:

I click the Edit Signal button, select the MAT-file, select the Block Name option and click the Map Signals button. The dialog will verify that the data in the MAT-file is compatible with the model and show you the result:

If the mapping is successful, you can click apply and the text in the Input: field will be updated:

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 comment here.

### 3 Responses to “The Easiest Way to Import Signals Into Your Model”

1. Eike Petersen replied on :

First of all, I must confess that I have not used this feature before, since I did not know about it.
However, I think I would only like it for doing quick and dirty testing of a model that I currently develop and not for larger projects. The reason is that I have to touch/modify (if I understood you correctly) the model everytime I want to switch between testing and referencing it. I prefer having a single model that I can reference in a test bench as well as in a larger application.
This leads me to another question: Is there an ‘officially recommended’ way of testing a model?

2. Guy Rouleau replied on :

@Eike: You are asking a very good question.

First, you are right when mentioning that the method described in this post modifies the configuration of the model.

However testing without a harness model is possible without modifying the model. It can done by specifying the input signals as an argument to the SIM command.

The most appropriate way of testing a model depends on what you are testing and on your preferences.

In Simulink Verification and Validation and Simulink Design Verifier, we offer functions like slvnvmakeharness and sldvmakeharness. Those functions create a harness model and use the Signal Builder block to store all the test cases. It is then possible to link the test cases to assertion blocks. This looks similar to the workflow you describe.

In SystemTest, the model is tested without a parent harness model. Test signals are passed directly to the root-level input ports.

3. Eike Petersen replied on :

@Guy: Thanks a lot for the quick reply! You mentioned several techniques that I wasn’t aware of and that sound pretty useful. Very interesting, I’ll have to try them soon!

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 3 + 5 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

Guy Rouleau and Seth Popinchalk are Application Engineers for MathWorks. They write here about Simulink and other MathWorks tools used in Model-Based Design.

These postings are the author's and don't necessarily represent the opinions of MathWorks.