{"id":3147,"date":"2014-01-15T13:06:08","date_gmt":"2014-01-15T18:06:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=3147"},"modified":"2017-08-28T20:33:59","modified_gmt":"2017-08-29T01:33:59","slug":"a-free-dialog-for-your-matlab-system-block","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2014\/01\/15\/a-free-dialog-for-your-matlab-system-block\/","title":{"rendered":"A Free Dialog for your MATLAB System Block"},"content":{"rendered":"<p><em>Today I am happy to welcome guest blogger Jacob Halbrooks to describe some nice capabilities of the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/matlab-system-block.html\">MATLAB System block<\/a> dialog.<\/em><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/Jacob_Profile.jpg\" alt=\"Jacob Halbrooks, guest blogger\" \/><\/p>\r\n\r\n<p>The MATLAB System block is new in R2013b and allows you to easily use a System object in Simulink. Guy introduced <a href=\"https:\/\/blogs.mathworks.com\/seth\/2013\/09\/11\/the-matlab-system-block\/\">System objects and the MATLAB System block<\/a>, and Revathi explored <a href=\"https:\/\/blogs.mathworks.com\/seth\/2013\/10\/24\/methods-of-the-matlab-system-block\/\">methods of the MATLAB System block<\/a>. Now we are going to look at the dialog for the MATLAB System block.<\/p>\r\n\r\n<p><strong>Mapping properties to parameters<\/strong><\/p>\r\n\r\n<p>In MATLAB, a System object has properties. In Simulink, blocks have parameters. When you specify a System object for use in a MATLAB System block, each public property becomes a parameter of the same name. Private or hidden properties do not become a parameter. I recommend going through the documentation page on <a title=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/define-property-attributes-1.html (link no longer works)\">Defining Property Attribute<\/a> if you are not familiar with this topic. <\/p>\r\n\r\n<p>Consider the following System object, designed especially to demonstrate the dialog features of the MATLAB System block:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/mask_system_object.png\" alt=\"Example System Object\" \/><\/p>\r\n\r\n<p>Let\u2019s <a href=\"\">create a MATLAB System block<\/a> with this System object:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/specifying_object.png\" alt=\"Creating a System Object Block\" \/><\/p>\r\n\r\n<p>We can immediately use <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/parameter-values-and-specification-methods.html\">any of the regular approaches<\/a> to query and set the block\u2019s parameters.  For example, I can obtain the value of parameters <tt>NumericValue<\/tt> and <tt>EnableCustomValue<\/tt> using:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/get_dialog_param.png\" alt=\"Dialog Parameters\" \/><\/p>\r\n\r\n<p><strong>Launching the dialog<\/strong><\/p>\r\n\r\n<p>An important feature of the MATLAB System block is that it provides a default dialog for its parameters. This free dialog is generated using information in the System object but without any need of custom methods or special coding. Let\u2019s double-click our block to launch its dialog:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/system_object_dialog.png\" alt=\"Dialog of the system Object\" \/><\/p>\r\n\r\n<p>We can see that each public property in the System object is represented in the dialog according to its attributes:<\/p>\r\n\r\n<ul>\r\n\t<li>The <tt>StringChoice<\/tt> property is a finite set of strings, or <tt>StringSet<\/tt>, so it contributes a drop-down menu<\/li>\r\n\t<li>The <tt>EnableCustomValue<\/tt> property is Logical, so it contributes a checkbox<\/li>\r\n\t<li>The numeric properties contribute edit boxes<\/li>\r\n<\/ul>\r\n\r\n<p>You can notice that the prompt for each parameter comes directly from the comments in the code, and the default value for each parameter is obtained from the property\u2019s default value.<\/p>\r\n\r\n<p>In addition to the Parameters section, each MATLAB System block dialog is provided a header and a drop-down menu to control whether to <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/simulation-modes.html\">simulate using code generation or interpreted execution<\/a>.<\/p>\r\n\r\n<p><strong>Hiding parameters<\/strong><\/p>\r\n\r\n<p>Our example System object uses the isInactivePropertyImpl method to control which properties are active. This can be observed in the dialog by toggling the checkbox. With the checkbox unchecked, the custom value edit box disappears and the dialog automatically resizes:<\/p>\r\n\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/configurable_dialog.png\" alt=\"Configurable Dialog\" \/><\/p>\r\n\r\n<p><strong>Customizing the dialog<\/strong><\/p>\r\n\r\n<p>While the default dialog provides a useful interface for any MATLAB System block, you may want to further customize it. For this purpose, you may implement these methods in the System object:<\/p>\r\n\r\n<ul>\r\n\t<li>getHeaderImpl: Customize header section of dialog, including title and description<\/li>\r\n\t<li>getPropertyGroupsImpl: Organize properties into groups to display as panels and tabs\r\n<\/ul>\r\n\r\n<p>For example, I can add the following method to the above example:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/with_tabs_code.png\" alt=\"Dialog with Tabs\" \/><\/p>\r\n\r\n<p>and the dialog now contains two tabs:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/with_tabs.png\" alt=\"Dialog with Tabs\" \/><\/p>\r\n\r\n<p><strong>Now it\u2019s your turn<\/strong><\/p>\r\n\r\n<p>Try your own System object in the MATLAB System block and explore its default dialog. Let us know what you think by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=3147&#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q1\/with_tabs.png\" onError=\"this.style.display ='none';\" \/><\/div><p>Today I am happy to welcome guest blogger Jacob Halbrooks to describe some nice capabilities of the MATLAB System block dialog.\r\n\r\n\r\n\r\nThe MATLAB System block is new in R2013b and allows you to... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2014\/01\/15\/a-free-dialog-for-your-matlab-system-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":[47,87],"tags":[346],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3147"}],"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=3147"}],"version-history":[{"count":39,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3147\/revisions"}],"predecessor-version":[{"id":6722,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3147\/revisions\/6722"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=3147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=3147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=3147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}