Main Content

Control Custom Tables Programmatically

You can add a custom table on the mask dialog box programmatically and control its properties using command line 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:

% Mask Object
maskObj = Simulink.Mask.create(gcb); 

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

% 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'}" ] );

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' );

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
changedCells = tableControl.getChangedCells(); 

% get value of a particular cell
tableControl.getValue( [rowIdx colIdx] ); 

% Set value for a particular cell
tableControl.setValue( [rowIdx colIdx], 'Value' );

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( [rowIdx colIdx], 'Type', 'checkbox', 'Value', 'off', 'Enabled', 'off' )

% get value from a particular table cell
tableCell = tableControl.getTableCell( [rowIdx colIdx] )
tableCell = 

  CustomTableParamCellObject with properties:

          Value: 'Inherit'
           Type: 'popup'
        Enabled: 'off'
    TypeOptions: {4×1 cell}

tableCell.Value = 'Value'


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

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( rowIndex, 'insertSig4', 'Input', 'Inherit', 'Inherit', 'on', 'Inherit' )

% Remove a particular row
tableControl.removeRow( rowIndex )

% Swap two rows
tableControl.swapRows( rowIndex1, rowIndex2 )

ans =

     3     4

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', 'HDL Name', 'Type', 'edit' ); 

% Insert a column at a particular location in the table
tableControl.insertColumn( columnIndex, 'Name', 'HDL Name', 'Type', 'edit' );

% Remove a column from the table
tableControl.removeColumn( columnIndex );

tableControl.getColumn( columnIndex );

For example,

tableControl.getColumn( 4 )
ans = 

  TableParamColumnInfo with properties:

           Name: 'Data Type'
           Type: 'popup'
        Enabled: 'on'
    TypeOptions: {4×1 cell}

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' }" )

Related Topics