{"id":1622,"date":"2013-01-17T23:48:33","date_gmt":"2013-01-18T04:48:33","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=1622"},"modified":"2013-01-17T23:48:33","modified_gmt":"2013-01-18T04:48:33","slug":"which-callback-should-i-use","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2013\/01\/17\/which-callback-should-i-use\/","title":{"rendered":"Which callback should I use?"},"content":{"rendered":"<p>This week's post has been triggered by question recently posted on this blog regarding <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012b\/simulink\/masking.html\">Masking<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012b\/simulink\/slref\/variantsubsystem.html\">Variant Subsystems<\/a>.<\/p>\r\n\r\n<p>If you look at <a href=\"https:\/\/blogs.mathworks.com\/seth\/2011\/10\/25\/dynamics-mask-icons-for-subsystem-variants\/#comment-2853\">this exchange<\/a> I had with Xiaojun Yang, you will see that it ends up with the common question:<\/p>\r\n\r\n<p><em>Which callback function is appropriate choice if it\u2019s such a case?<\/em><\/p>\r\n\r\n<p><strong>Which callback should I use?<\/strong><\/p>\r\n\r\n<p>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.\r\n\r\n<p>As you probably know, you have <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/using-callback-functions.html#f4-93072\">model callbacks<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/using-callback-functions.html#f4-93098\">block callbacks<\/a>.<\/p>\r\n\r\n<p>For masked subsystems, you typically have two types of callbacks. For each parameter, you have a dialog callback:<\/p>\r\n\r\n<p><a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/dialogCallbacks_large.png\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/dialogCallbacks.png\" alt=\"Dialog callbacks\" \/><\/a><\/p>\r\n\r\n<p>and you have initialization commands:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/maskInitialization.png\" alt=\"Mask Initialization\" \/><\/p>\r\n\r\n<p>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.<\/p>\r\n\r\n<p><strong>Best Practices for Masking<\/strong><\/p>\r\n\r\n<p>In R2012b, if you search the documentation for \"masking examples\", you will notice that the first result is:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/MaskingDocSearch.png\" alt=\"Masking Examples\" \/><\/p>\r\n\r\n<p>In the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/masking-example-models.html\">Best Practices for Masking<\/a> page, there are detailed examples showing how to achieve common masking tasks:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/MaskingDoc.png\" alt=\"Masking Examples\" \/><\/p>\r\n\r\n<p>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.<\/p>\r\n\r\n<p><a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/masking_examples_overview.png\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/masking_examples_overview_small.png\" alt=\"Masking Examples\" \/><\/a><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Give a look at the examples included in <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/masking-example-models.html\">Best Practices for Masking<\/a> and let us know if there are additional examples you would like to see by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=1622&#comment\">comment here<\/a><\/p>\r\n \r\n\r\n\r\n\r\n\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q4\/masking_examples_overview_small.png\" onError=\"this.style.display ='none';\" \/><\/div><p>This week's post has been triggered by question recently posted on this blog regarding Masking and Variant Subsystems.\r\n\r\nIf you look at this exchange I had with Xiaojun Yang, you will see that it... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2013\/01\/17\/which-callback-should-i-use\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[47,16],"tags":[306,305],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1622"}],"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=1622"}],"version-history":[{"count":28,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1622\/revisions"}],"predecessor-version":[{"id":1831,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1622\/revisions\/1831"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=1622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=1622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=1622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}