Main Content

Control Custom Table Programmatically

Use a programmatic interface to control custom tables. You can add a custom table on the mask dialog box programmatically and control its properties using programmatic interface. For information on creating a custom table from the Mask Editor, see Customize Tables for Masked Blocks.

Add a Custom Table Parameter

You can add a custom table parameter to a mask dialog box using these commands:

Warning: The model name 'mask_custom_table' is shadowing another name in the MATLAB workspace or path. Type "which -all mask_custom_table" at the command line to find the other uses of this name. You should change the name of the model to avoid problems.
% Mask Object
maskObj = Simulink.Mask.create(gcb); 

% Add custom table parameter
tableParam = maskObj.addParameter( 'Name', 'myTable', 'Type', 'customtable' );

Add Columns to a Table

You can add columns to a custom table using the addColumn command:

tableControl = maskObj.getDialogControl('myTable');
tableControl.addColumn( 'Name', 'HDL Name', 'Type', 'edit' );
tableControl.addColumn( 'Name', 'I/O Mode', 'Type', 'popup', 'TypeOptions', {'Input', 'Output'} );
tableControl.addColumn( 'Name', 'Sample Time', 'Type', 'edit' );
tableControl.addColumn( 'Name', 'Data Type', 'Type', 'popup', 'TypeOptions', {'Inherit', 'FixedPoint', 'Double', 'Single'} );
tableControl.addColumn( 'Name', 'Sign', 'Type', 'checkbox' );
tableControl.addColumn( 'Name', 'Fraction Length', 'Type', 'edit' );
tableControl = 
  CustomTable with properties:

                 Name: 'myTable'
                  Row: 'new'
    HorizontalStretch: 'on'
              Tooltip: ''
           ShowFilter: 'on'
          Multiselect: 'on'
             Sortable: 'off'
              Columns: [1×6 Simulink.Mask.TableParamColumnInfo]

% Add values to the table
tableParam.Value = join( [ "{'sig1', 'Input', 'Inherit', 'Inherit', 'on',  'Inherit';",  ...
                           " 'sig2', 'Input', 'Inherit', 'Inherit', 'on',  'Inherit';",  ...
                           " 'sig3', 'Output', '10',     'Inherit', 'off', 'Inherit';",  ...
                           " 'sig4', 'Output', '10',     'Inherit', 'off', 'Inherit'}" ] );


  • You can use the Width property to specify initial column width for a custom table.

Set and Get Table Properties

You can fetch the value of a cell if it had a change and set a new value for a cell in the table using these commands:

% get values of the changed cell

% get value of a particular cell
tableControl.getValue( [1 3] ); 

% Set value for a particular cell
tableControl.setValue( [1 3], '20' );

changedCells = tableControl.getChangedCells(); 

Set and Get Cell Level Specifications

You can set and fetch the value of a particular cell in a custom table. The commands used are:

% set value for a particular table cell
tableControl.setTableCell( [1 3], 'Type', 'checkbox', 'Value', 'off', 'Enabled', 'off' )

% get value from a particular table cell
tableCell = tableControl.getTableCell( [1 5] )
tableCell = 
  CustomTableParamCellObject with properties:

          Value: 'on'
           Type: 'checkbox'
        Enabled: 'on'
    TypeOptions: {0×1 cell}


  • The setTableCell and getTableCell APIs must be used as part of mask parameter call backs while getting the number of rows in a table.

  • The setTableCell and getTableCell APIs displays the correct result only when the dialog with the custom table parameter is opened.

Edit Rows in a Custom Table

You can insert, remove, swap, and get the value of a specific row in a custom table. The commands used are:

% add a row to the table
tableControl.addRow( 'sig5', 'Input', 'Inherit', 'Inherit', 'on', 'Inherit' ) 

% Insert a row at a specific location in the table
tableControl.insertRow( 4, 'insertSig4', 'Input', 'Inherit', 'Inherit', 'on', 'Inherit' )

% Remove a particular row
tableControl.removeRow( 2 )

% Swap two rows
tableControl.swapRows( 3, 4 )


Get and Set Table Parameter

You can use the set_param and get_param commands to set or get the values of the custom table parameter you created in a mask dialog box.

get_param( gcb, 'myTable' )
ans = 
'{'sig1', 'Input', 'Inherit', 'Inherit', 'on',  'Inherit';  'sig2', 'Input', 'Inherit', 'Inherit', 'on',  'Inherit';  'sig3', 'Output', '10',     'Inherit', 'off', 'Inherit';  'sig4', 'Output', '10',     'Inherit', 'off', 'Inherit'}'
set_param( gcb, 'myTable', "{ 'sig1', 'Input', 'Inherit', 'Inherit', 'on', 'Inherit' }" )

Edit Columns in a Custom Table

You can insert, remove, swap, and get the value of a specific column in a custom table. The commands used are:

% add a column to the table
tableControl.addColumn( 'Name', 'Hardware Name', 'Type', 'edit' ); 
% Remove a column from the table
tableControl.removeColumn( 1 );
% Insert a column at a particular location in the table
tableControl.insertColumn( 1, 'Name', 'HDL Name', 'Type', 'edit' );
tableControl.getColumn( 4 );

Insert Column and Enable Evaluation of the Column Cells

Insert a new column with the Evaluate check box selected. The command used is:

tableControl.insertColumn( 2, 'Name', 'Counter', 'Type', 'edit','Evaluate','on' ); 

Related Topics