{"id":4628,"date":"2013-06-14T09:00:53","date_gmt":"2013-06-14T13:00:53","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4628"},"modified":"2016-05-10T08:34:47","modified_gmt":"2016-05-10T12:34:47","slug":"change-your-mask-change-your-look","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/06\/14\/change-your-mask-change-your-look\/","title":{"rendered":"Change Your Mask, Change Your Look!"},"content":{"rendered":"\r\n<div class=\"content\"><!--introduction--><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\">Greg's<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/36018-dynamic-mask-field-changing-from-selected-pulldown-menu\">Dynamic Mask Field Changing From Selected Pulldown Menu<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/142770\">David Manegold<\/a>.<\/p><p>Ever wanted to change how your Simulink block mask appears depending on certain parameter conditions of the mask?  David has a nice example.<\/p><p>I selected this submission because it demonstrates an advanced Simulink development technique in a straight-forward manner.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#0d5a9004-ad3d-4549-993a-3542907d813f\">Change Thy Appearance, and Quick!<\/a><\/li><li><a href=\"#b67db82d-392e-4da2-8c88-2eebbc28bd30\">What Doest Thou Hide Behind the Mask?<\/a><\/li><li><a href=\"#83f28952-8b24-42c9-9ccc-b6f39b628847\">Mask, Reveal Thy Magic!<\/a><\/li><\/ul><\/div><h4>Change Thy Appearance, and Quick!<a name=\"0d5a9004-ad3d-4549-993a-3542907d813f\"><\/a><\/h4><p>Masks have the ability to change what parameters are available depending on which parameters have been selected. In this example, if the value of the \"Selector\" parameters is \"A\" then the set of parameters associated with \"A\" appears in the mask. But if you select \"C\" instead, then a new set of parameters is displayed. Also option \"C\" has a subset of parameters that can also change depending on what you choose for \"C alt field type 3\".<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/Dynamic_Masks\/maskSelectorA.png\" alt=\"\"> <\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/Dynamic_Masks\/maskSelectorC.png\" alt=\"\"> <\/p><h4>What Doest Thou Hide Behind the Mask?<a name=\"b67db82d-392e-4da2-8c88-2eebbc28bd30\"><\/a><\/h4><p>The mask is a dialog box that appears when you double-click on a block in Simulink. It provides a means to enter parameters for a Simulink block or subsystem to affect its functionality. This means you can have two instances of a block or subsystem in the same model that exhibit different behavior depending on the parameter values entered in the mask. You can create your own masks for subsystems or blocks by right-clicking on the block and select<\/p><p><i>Mask -&gt; Create mask...<\/i><\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/Dynamic_Masks\/createMask.png\" alt=\"\"> <\/p><p>For more information on creating masks see <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/how-to-mask-a-block.html\">Create Mask Documentation<\/a>.<\/p><h4>Mask, Reveal Thy Magic!<a name=\"83f28952-8b24-42c9-9ccc-b6f39b628847\"><\/a><\/h4><p>David leverages two capabilities to enable this behavior in a block mask.<\/p><div><ol><li>Mask parameter callback function<\/li><li>The MaskVisibilities property of the block<\/li><\/ol><\/div><p>In the mask editor, if you select a parameter to edit, you can populate the \"Dialog callback\" field to execute MATLAB functions that get executed when the parameter is changed in the block mask.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/Dynamic_Masks\/maskParameterCallback.png\" alt=\"\"> <\/p><p>Within the callback function ChangeMaskFields, David changes the visibility of specific parameters based on the value of the \"Selector\" parameter. He defaults the parameter visibilities to \"off\":<\/p><pre class=\"language-matlab\">[M{:}]=deal(<span class=\"string\">'off'<\/span>);\r\n<\/pre><p>except for the first parameter (which is the Selector parameter):<\/p><pre class=\"language-matlab\">M{1}=<span class=\"string\">'on'<\/span>;\r\n<\/pre><p>Then he enables specific parameters based on the value of the \"Selector\" parameter:<\/p><pre class=\"language-matlab\">[M{i0:ie}]=deal(<span class=\"string\">'on'<\/span>);\r\n<\/pre><p><b>Comments<\/b><\/p><p>If you would like to leave any comments regarding this post, please click <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4628#respond\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_8d643d9cf06049f496e991a2a37dfd69() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='8d643d9cf06049f496e991a2a37dfd69 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 8d643d9cf06049f496e991a2a37dfd69';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_8d643d9cf06049f496e991a2a37dfd69()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><\/div><!--\r\n8d643d9cf06049f496e991a2a37dfd69 ##### SOURCE BEGIN #####\r\n%% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\r\n% Greg's> pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/36018-dynamic-mask-field-changing-from-selected-pulldown-menu\r\n% Dynamic Mask Field Changing From Selected Pulldown Menu> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/142770 David\r\n% Manegold>.\r\n% \r\n% Ever wanted to change how your Simulink block mask appears depending on\r\n% certain parameter conditions of the mask?  David has a nice example. \r\n%\r\n% I selected this submission because it demonstrates an advanced Simulink\r\n% development technique in a straight-forward manner.\r\n\r\n%% Change Thy Appearance, and Quick! \r\n% Masks have the ability to change what parameters are available\r\n% depending on which parameters have been selected. In this example, if the\r\n% value of the \"Selector\" parameters is \"A\" then the set of parameters\r\n% associated with \"A\" appears in the mask. But if you select \"C\" instead,\r\n% then a new set of parameters is displayed. Also option \"C\" has a subset\r\n% of parameters that can also change depending on what you choose for \"C\r\n% alt field type 3\".\r\n% \r\n% <<maskSelectorA.png>>\r\n% \r\n% <<maskSelectorC.png>>\r\n%\r\n\r\n%% What Doest Thou Hide Behind the Mask?\r\n% The mask is a dialog box that appears when you double-click on a block in\r\n% Simulink. It provides a means to enter parameters for a Simulink block\r\n% or subsystem to affect its functionality. This means you can have two\r\n% instances of a block or subsystem in the same model that exhibit\r\n% different behavior depending on the parameter values entered in the mask.\r\n% You can create your own masks for subsystems or blocks by right-clicking\r\n% on the block and select\r\n% \r\n% _Mask -> Create mask..._\r\n%  \r\n% <<createMask.png>>\r\n% \r\n% For more information on creating masks see\r\n% <https:\/\/www.mathworks.com\/help\/simulink\/ug\/create-mask-documentation.html\r\n% Create Mask Documentation>.\r\n% \r\n%% Mask, Reveal Thy Magic!\r\n% David leverages two capabilities to enable this behavior in a block mask.\r\n%\r\n% # Mask parameter callback function\r\n% # The MaskVisibilities property of the block\r\n% \r\n% In the mask editor, if you select a parameter to edit, you can populate\r\n% the \"Dialog callback\" field to execute MATLAB functions that get executed\r\n% when the parameter is changed in the block mask.\r\n% \r\n% \r\n% <<maskParameterCallback.png>>\r\n% \r\n% Within the callback function ChangeMaskFields, David changes the\r\n% visibility of specific parameters based on the value of the \"Selector\"\r\n% parameter. He defaults the parameter visibilities to \"off\":\r\n% \r\n%   [M{:}]=deal('off');\r\n% \r\n% except for the first parameter (which is the Selector parameter):\r\n% \r\n%   M{1}='on';\r\n% \r\n% Then he enables specific parameters based on the value of the \"Selector\"\r\n% parameter:\r\n%\r\n%   [M{i0:ie}]=deal('on');\r\n% \r\n%%\r\n% *Comments*\r\n%\r\n% If you would like to leave any comments regarding this post, please click \r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4628#respond here>. \r\n\r\n\r\n##### SOURCE END ##### 8d643d9cf06049f496e991a2a37dfd69\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/Dynamic_Masks\/maskSelectorA.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\nGreg's pick this week is Dynamic Mask Field Changing From Selected Pulldown Menu by David Manegold.Ever wanted to change how your Simulink block mask appears depending on certain parameter... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/06\/14\/change-your-mask-change-your-look\/\">read more >><\/a><\/p>","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4628"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4628"}],"version-history":[{"count":9,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4628\/revisions"}],"predecessor-version":[{"id":6909,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4628\/revisions\/6909"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}