Main Content

Create a Custom Table in the Mask Dialog

This example shows how to create a custom table in a mask dialog. This model includes a Subsystem block with a mask on it. The mask has a callback that modifies the table content based on the values provided in the cells. The callback comes from an external supporting file. To create this table, start by adding a mask to the block or editing an existing mask.

Add and Configure a Custom Table parameter

To add a Custom Table parameter, open the Mask Editor,go to the Parameters & Dialog tab and click Custom Table. Then, add values in the Property editor section. For this example, in the Value field, add:

{ 'sig1', 'Input', 'Inherit', 'Inherit', 'Signed', 'Inherit'; 'sig2', 'Input', 'Inherit', 'Inherit', 'Signed', 'Inherit'; 'sig3', 'Output', '10', 'Inherit', 'Signed', 'Inherit'; 'sig4', 'Output', '10', 'Inherit', 'Signed', 'Inherit' }.

In the Columns field, click the Edit icon and add the name of columns. The column names used in this example are: HDL Name, I/O Mode, Sample Time, Data Type, Sign, and Fraction Length.

In the Dialog section, edit the Callback field to add your callback. The callback used in this example is from an external file named CustomTableCallback.m. Enter the filename in the callback field. This callback defines how the values change in a cell based on the value from other cells and columns.

Add Buttons and Options to Control the Custom Table

In this example, four buttons are added to add a new row, delete a selected row, and move a row up or down. To add the buttons, in the Action section click the Button parameter four times. Name the buttons as New, Delete, Up, and Down. To configure the buttons, edit the Callback field in the Property editor and add the appropriate callbacks. The callback used for each button is:

New

maskObj = Simulink.Mask.get(gcb);
tableControl = maskObj.getDialogControl( 'CustomTable' );
hdlName =  'sig';
rowIndex = tableControl.getNumberOfRows();
hdlName = strcat( 'sig', num2str( rowIndex + 1 ) );
tableControl.addRow( hdlName, 'Input', 'Inherit', 'Inherit', 'Signed', 'Inherit' )

Delete

maskObj = Simulink.Mask.get(gcb);
tableControl = maskObj.getDialogControl( 'CustomTable' );
rowIndex = tableControl.getSelectedRows();
hdlName =  'sig';
if ( ~isempty(rowIndex) )
    tableControl.removeRow( rowIndex(1) );
end

Up

maskObj = Simulink.Mask.get(gcb);
tableControl = maskObj.getDialogControl( 'CustomTable' );
rowIndex = tableControl.getSelectedRows();
if ( ~isempty(rowIndex) )
    tableControl.swapRows( rowIndex(1)-1, rowIndex(1) );
end

Down

maskObj = Simulink.Mask.get(gcb);
tableControl = maskObj.getDialogControl( 'CustomTable' );
rowIndex = tableControl.getSelectedRows();
if ( ~isempty(rowIndex) )
    tableControl.swapRows( rowIndex(1)+1, rowIndex(1) );
end

In addition to these buttons, the table also has a check box to enable direct feedthrough and an autofill button that automatically creates the signal interface from a specified HDL component instance. To add these options, add a check box and a button control and add the appropriate configurations.

After adding all the values, click OK to save the changes. You can preview the table using the Preview button. This is a preview of the final table created in this example: