A Free Dialog for your MATLAB System Block
Today I am happy to welcome guest blogger Jacob Halbrooks to describe some nice capabilities of the MATLAB System block dialog.
The MATLAB System block is new in R2013b and allows you to easily use a System object in Simulink. Guy introduced System objects and the MATLAB System block, and Revathi explored methods of the MATLAB System block. Now we are going to look at the dialog for the MATLAB System block.
Mapping properties to parameters
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 Defining Property Attribute if you are not familiar with this topic.
Consider the following System object, designed especially to demonstrate the dialog features of the MATLAB System block:
Let’s create a MATLAB System block with this System object:
We can immediately use any of the regular approaches to query and set the block’s parameters. For example, I can obtain the value of parameters NumericValue and EnableCustomValue using:
Launching the dialog
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’s double-click our block to launch its dialog:
We can see that each public property in the System object is represented in the dialog according to its attributes:
- The StringChoice property is a finite set of strings, or StringSet, so it contributes a drop-down menu
- The EnableCustomValue property is Logical, so it contributes a checkbox
- The numeric properties contribute edit boxes
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’s default value.
In addition to the Parameters section, each MATLAB System block dialog is provided a header and a drop-down menu to control whether to simulate using code generation or interpreted execution.
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:
Customizing the dialog
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:
- getHeaderImpl: Customize header section of dialog, including title and description
- getPropertyGroupsImpl: Organize properties into groups to display as panels and tabs
For example, I can add the following method to the above example:
and the dialog now contains two tabs:
Now it’s your turn
Try your own System object in the MATLAB System block and explore its default dialog. Let us know what you think by leaving a comment here.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.