Guy on Simulink

Simulink & Model-Based Design

Why you should use the Function-Call Split block

Today I had a good discussion with a user regarding the Function-Call Split block introduced in R2010a.

On one side, the user claimed that there was no need for a Function-Call Split block. For example, in the following model the Demux block can be used to obtain results similar to the Function-Call Split block.

Comparison between Demux and Split

I personally think that there are many reasons why you should always use the Function-Call Split block and avoid using the Demux block to manipulate Function-call signals.

Really Splitting One Function-Call

In the previous model, the Demux block can be used to split the function-call because it originates from the Function-Call Generator block. To be accurate, in that case we need to notice that the Demux block does not split one function call... it is the Function-Call generator block that generates 2 function calls. As shown in the image below, a dimension 2 is specified in the Demux block and back-propagated to the Function-Call Generator... resulting in a not very obvious case of scalar expansion.

Back Propagation of Fcn-Call dimension

If you try the same with a function-call generated by a MATLAB Function block or a Stateflow chart, you will get an error. To split a function call from one of those, you need to use the Function-Call Split block.

Using a Split to split function-call generated by the MATLAB Function block

Data Dependency Checking

If you implement the following model, it will simulate and generate code without error or warning. When this happens in a large model, it might not be obvious to the user that there is an implicit delay because A runs before B, but requires data from B.

Feedback with Demux

If you use the Function-Call Split block, you will get a clear error message explaining your options. If the delay was not expected, you can rearrange the order of your function-calls. If the delay is expected, then you can insert a Function-Call Feedback Latch block to explicitly specify it.

Feedback with Split

Better Display of Sorted Order

Let's say you write an S-function that generates a vector of two function-call signals and you separate them using a Demux block. Just by looking at the model, it is impossible to know in which order the function-call subsystems will execute. If you display the sorted order all the destinations are marked identically in the format S:F.

Sorted Order with Demux

With the Function-Call Split block, everything becomes clearer. Only one function-call signal is generated by the source, and the order into which the function-call subsystems execute is displayed with a format S:B#, where # is the order of the branch.

Sorted Order with Split

Now it's your turn

What do you think of the Function-Call Split block? Let us know by leaving a comment here.

|
  • print

Comments

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