プログラムによるカスタム テーブルの制御
プログラムによるインターフェイスを使用してカスタム テーブルを制御する。マスク ダイアログ ボックスでカスタム テーブルをプログラムにより追加し、そのプロパティをプログラムによるインターフェイスを使用して制御できます。マスク エディターからカスタム テーブルを作成する詳細については、マスクされたブロックのテーブルのカスタマイズを参照してください。
カスタム テーブル パラメーターの追加
以下のコマンドを使用して、カスタム テーブル パラメーターをマスク ダイアログ ボックスに追加できます。
new_system('mask_custom_table');
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.
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' );
テーブルへの列の追加
addColumn
コマンドを使用して列をカスタム テーブルに追加できます。
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: [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'}" ] );
メモ:
"Width" プロパティを使用してカスタム テーブルの初期の列幅を指定できます。
テーブル プロパティの設定と取得
セルに変更があった場合は、以下のコマンドを使用してその値を取得し、テーブル内のセルに対して新しい値を設定できます。
% 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 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}
メモ:
setTableCell API と getTableCell API は、テーブル内の行数を取得している間にマスク パラメーターのコールバックの一部として使用しなければなりません。
setTableCell API と getTableCell API は、カスタム テーブル パラメーターを含むダイアログが開いたときにのみ正しい結果を表示します。
カスタム テーブルの行の編集
カスタム テーブルで特定の行の値を挿入、削除、交換、および取得できます。使用するコマンドは次のとおりです。
% 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()
テーブル パラメーターの取得および設定
set_param
コマンドと get_param
コマンドを使用して、マスク ダイアログ ボックスで作成したカスタム テーブル パラメーターの値を設定または取得できます。
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' }" )
カスタム テーブルの列の編集
カスタム テーブルで特定の列の値を挿入、削除、交換、および取得できます。使用するコマンドは次のとおりです。
% 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 );
列の挿入と列セルの評価の有効化
[評価] チェック ボックスがオンになっている新しい列を挿入します。使用するコマンドは次のとおりです。
tableControl.insertColumn( 2, 'Name', 'Counter', 'Type', 'edit','Evaluate','on' );