This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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', 'Evaluate', 'off' );

% Add values to the table
tableParam.Value = "{ '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'} );

Get and Set 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' );

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', "{ 'Hello', 'Input', 'Inherit', 'Inherit',...
 'on', 'Inherit'; 'sig2', 'Input', 'Inherit', 'Inherit', 'on', 'Inherit'; ...
'sig3', 'Output', '10', 'Inherit', 'off', 'Inherit'; 'sig4', 'Output', '10',...
 'Inherit', 'off', 'Inherit' }" )

See Also