Main Content

Control Custom Table Programatically

Use Command Line Interface to control custom tables. 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:

new_system('mask_custom_table');
add_block('built-in/subsystem','mask_custom_table/subsystem');
save_system;
open_system('mask_custom_table');
% 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.Columns(2).Width=500
tableControl = 
  CustomTable with properties:

                 Name: 'myTable'
                  Row: 'new'
    HorizontalStretch: 'on'
              Tooltip: ''
           ShowFilter: 'on'
          Multiselect: 'on'
             Sortable: 'off'
              Columns: [1x6 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'}" ] );

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
open_system('mask_custom_table/subsystem')

% 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: {0x1 cell}

Note:

  • 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 )

tableControl.getSelectedRows()

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', 'off', 'Inherit', 'on', 'Inherit'; 'sig3', 'Output', '10', 'Inherit', 'off', 'Inherit'; 'sig4', 'Output', '10', 'Inherit', 'off', 'Inherit'; 'insertSig4', 'Input', 'Inherit', 'Inherit', 'on', 'Inherit'; 'sig5', 'Input', 'Inherit', 'Inherit', 'on', '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 );

Related Topics