{"id":2311,"date":"2013-07-16T16:58:09","date_gmt":"2013-07-16T21:58:09","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=2311"},"modified":"2017-04-27T09:01:33","modified_gmt":"2017-04-27T14:01:33","slug":"why-you-should-use-the-function-call-split-block","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2013\/07\/16\/why-you-should-use-the-function-call-split-block\/","title":{"rendered":"Why you should use the Function-Call Split block"},"content":{"rendered":"<p>Today I had a good discussion with a user regarding the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallsplit.html\">Function-Call Split<\/a> block introduced in R2010a.<\/p>\r\n\r\n<p>On one side, the user claimed that there was no need for a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallsplit.html\">Function-Call Split<\/a> block. For example, in the following model the Demux block can be used to obtain results similar to the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallsplit.html\">Function-Call Split<\/a> block.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/equivalentFcnCallModels.png\" alt=\"Comparison between Demux and Split\" \/><\/p>\r\n\r\n<p>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.\r\n\r\n<p><strong>Really Splitting One Function-Call<\/strong><\/p>\r\n\r\n<p>In the previous model, the Demux block can be used to split the function-call because it originates from the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallgenerator.html\">Function-Call Generator<\/a> 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 <a href=\"https:\/\/blogs.mathworks.com\/loren\/2006\/02\/22\/scalar-expansion-and-more-take-2\/\">scalar expansion<\/a>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/ScalarExpension.png\" alt=\"Back Propagation of Fcn-Call dimension\" \/><\/p>\r\n\r\n<p>If you try the same with a function-call generated by a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/matlabfunction.html\">MATLAB Function<\/a> block or a <a href=\"https:\/\/www.mathworks.com\/products\/stateflow\/\">Stateflow<\/a> chart, you will get an error. To split a function call from one of those, you need to use the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallsplit.html\">Function-Call Split<\/a> block.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/fcnCallFromMlFunction.png\" alt=\"Using a Split to split function-call generated by the MATLAB Function block\" \/><\/p>\r\n\r\n<p><strong>Data Dependency Checking<\/strong><\/p>\r\n\r\n<p>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.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/feedbackWithDemux.png\" alt=\"Feedback with Demux\" \/><\/p>\r\n\r\n<p>If you use the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallsplit.html\">Function-Call Split<\/a> 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 <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallfeedbacklatch.html\">Function-Call Feedback Latch<\/a> block to explicitly specify it.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/feedbackWithSplit.png\" alt=\"Feedback with Split\" \/><\/p>\r\n\r\n<p><strong>Better Display of Sorted Order<\/strong><\/p>\r\n\r\n<p>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 <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/controlling-and-displaying-the-sorted-order.html\">sorted order<\/a> all the destinations are marked identically in the format <tt><strong>S:F<\/strong><\/tt>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/sortedOrderDemux.png\" alt=\"Sorted Order with Demux\" \/><\/p>\r\n\r\n<p>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 <tt><strong>S:B#<\/strong><\/tt>, where <tt><strong>#<\/tt><\/strong> is the order of the branch.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/sortedOrderSplit.png\" alt=\"Sorted Order with Split\" \/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>What do you think of the Function-Call Split block? Let us know by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=2311&#comment\">comment here<\/a>.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q2\/sortedOrderSplit.png\" onError=\"this.style.display ='none';\" \/><\/div><p>Today I had a good discussion with a user regarding the Function-Call Split block introduced in R2010a.\r\n\r\nOn one side, the user claimed that there was no need for a Function-Call Split block. For... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2013\/07\/16\/why-you-should-use-the-function-call-split-block\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,33],"tags":[332],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2311"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=2311"}],"version-history":[{"count":39,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2311\/revisions"}],"predecessor-version":[{"id":6514,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/2311\/revisions\/6514"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=2311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=2311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=2311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}