# Guy and Seth on Simulink

## Which callback should I use?

This week's post has been triggered by question recently posted on this blog regarding Masking and Variant Subsystems.

If you look at this exchange I had with Xiaojun Yang, you will see that it ends up with the common question:

Which callback function is appropriate choice if it’s such a case?

Which callback should I use?

I have to admit, in Simulink there are many callbacks available and it is not always obvious which one should be used for a specific task.

As you probably know, you have model callbacks and block callbacks.

For masked subsystems, you typically have two types of callbacks. For each parameter, you have a dialog callback:

and you have initialization commands:

Even though they can sometime be interchanged, those two types of callback are intended for different use cases and using the wrong one can lead to unexpected behavior.

In R2012b, if you search the documentation for "masking examples", you will notice that the first result is:

In the Best Practices for Masking page, there are detailed examples showing how to achieve common masking tasks:

In your MATLAB installation, each of these links open a model with annotations and detailed comments in each callback to give you the starting point to develop your own masks.

Give a look at the examples included in Best Practices for Masking and let us know if there are additional examples you would like to see by leaving a comment here

### One Response to “Which callback should I use?”

1. Smith Joelson replied on :

Hey everyone. I am working on simulink and plotting some graphs on scopes. The time I change the simulation time, for example to 10s only the portion of the graph from 9s to 10s is shown. Nothing shows up between 0s and 9s. When I vary the time to 5s same thing happens, only 4-5 seconds interval is shown. How can I rectify this?

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

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.