Guy on Simulink

Simulink & Model-Based Design

Leveraging Model Comparison to find what you need

Today I want to share an example of how I sometimes use Model Comparison to answer questions about Simulink blocks or models. While this is obviously a key part of the workflow to merge branches in a project under source control as I described in Three-Way Model Merge and Git, model comparison can also be used to answer subtle "how-to" questions.
Let's look at a simple example question I received today and how I used model comparison to answer it.

The Question

The question I received today is:
"Hi Guy, do you know of a programmatic way to flip a block on the horizontal axis?"
I did not know the response off the top of my head, but here is how I figured it out.

Before and After

The first thing I do in this kind of situation is making an example to confirm my understanding of the question. For that, I created a simple Subsystem with a few ports all around and masked it to make the behavior as obvious as possible.
Then I made the requested modification interactively, using the Format Tab of the toolstrip:

Comparing Before and After

I saved two versions of this simple model, one before the change, and one after. Then I simply right-clicked on the two files in the Current Folder Browser and selected Compare Selected Files/Folders:
In the comparison results, I disabled the filter for Nonfunctional Changes and I could immediately identify the two parameters needed to flip a block horizontally:

Validating the Results

To confirm that the parameters identified by the Model Comparison were what I needed, I wrote this simple script:

Now it's your turn

Are you sometimes using the Model Comparison tool to identify subtle differences between blocks, Subsystems or models? Or to find the parameter you are looking for?
Let us know in the comments below.
  • print
  • send email


要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。