Guy on Simulink

Simulink & Model-Based Design

Are you using the right block?

Working in technical support, I receive a lot of models. Sometimes I am impressed by very clever implementations, but sometimes the only thing coming to my mind is "Why is he doing that?". Here are a few examples I want to share with you.

What time is it?

At least once per month, I receive a model where the To Workspace block is used to record the simulation time from a Clock block:

How to log time, bad example

It is not necessary to add blocks to your model. Instead, open the simulation Configuration Parameter and go to the Data Import/Export pane.

How to log time, good example

Abusing the MATLAB Function block

I saw this construct in a model recently:

Using the MATLAB Function block to separate components or a signal

Yes... this works. But using the MATLAB Function block for a task that a basic block can do makes your life more complicated than it should be. In this case, I recommend using the Demux block if you want to extract all the elements of the vector and Selector blocks if you only want a subset. It is faster to setup and does not require code generation when you hit play.

Using the Demux block or Selector to separate components or a signal

How do you Delay?

When searching for a block to delay a signal, here is what you find:

Searching for delays in the Simulink Library Browser

Which one do you pick? At first look, the Integer Delay block and the Transport Delay block might seem to give similar results:

Comparing Integer Delay and Transport Delay

However, when enabling the sample time colors and looking a bit closer at the results, you quickly notice that the Integer Delay block is discrete, while the Transport Delay is continuous.

Comparing Integer Delay and Transport Delay

Make sure you use the right block for your situation. The Integer Delay should be used for discrete signals, and the Transport Delay for continuous signals.

Now it's your turn

Do you encounter situations where you are not sure if you are using the right block? Have you ever been told you were using the wrong block? Please share with us by leaving a comment here.

|

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.