You can import table and breakpoint data from variables in the MATLAB workspace by referencing them in theTable and Breakpointstab of the dialog box. The following examples show how to import and export standard format and non-standard format data from the MATLAB workspace.
Suppose you specify a 3-D lookup table in your n-D Lookup Table block.
Create workspace variables to use as breakpoint and table data for the lookup table.
table3d_map = zeros(2,4,3); table3d_map(:,:,1) = [ 1 2 3 4; 5 6 7 8]; table3d_map(:,:,2) = [ 11 12 13 14; 15 16 17 18]; table3d_map(:,:,3) = [ 111 112 113 114; 115 116 117 118]; bp3d_z =[ 0 10 20]; bp3d_x =[ 0 10 20 30]; bp3d_y =[ 400 6400];
Table data: table3d_map
Breakpoints 1: bp3d_y
Breakpoints 2: bp3d_x
Breakpoints 3: bp3d_z
ClickEdit table and breakpointsto open the Lookup Table Editor and show the data from the workspace variables.
当你改变你的查找表数据,consider propagating the changes back to the MATLAB workspace variables the data was imported from usingFile>Update Block Data.
You can also use the Lookup Table Editor to edit the table data and breakpoint data set ofSimulink.LookupTable
and the breakpoint data set ofSimulink.Breakpoint
objects and propagate the changes back to the object.
Suppose you make a change to the lookup table variables imported from the MATLAB workspace variables inImport Standard Format Lookup Table Data. For example, change the value of the data in (1,1,1) from1
to33
. To propagate this change back totable3d_map
in the workspace, selectFile>Update Block Data. ClickYesto confirm that you want to overwritetable3d_map
.
Suppose you specify a 3-D lookup table in your n-D Lookup Table block. Create workspace variables to use as breakpoint and table data for the lookup table. The variable for table data,table3d_map_custom
, is a two-dimensional matrix.
table3d_map_custom = zeros(6,4); table3d_map_custom = [ 1 2 3 4; 5 6 7 8; 11 12 13 14; 15 16 17 18; 111 112 113 114; 115 116 117 118]; bp3d_z =[ 0 10 20]; bp3d_x =[ 0 10 20 30]; bp3d_y =[ 400 6400];
table3d_map_custom
into a three-dimensional matrix for the table data input using thereshape
command.
Table data:reshape(table3d_map_custom,[2,4,3])
Breakpoints 1:bp3d_y
Breakpoints 2:bp3d_x
Breakpoints 3:bp3d_z
ClickEdit table and breakpointsto open the Lookup Table Editor and show the data from the workspace variables.
Change 1 to 33 in the Lookup Table Editor. The Lookup Table Editor records your changes by maintaining a copy of the table. To restore the variable values from the MATLAB®workspace, selectFile>Reload Block Data. To update the MATLAB workspace variables with the edited data, selectFile>Update Block Datain the Lookup Table Editor. You cannot propagate the change totable3d_map_custom
, the workspace variable that contains the nonstandard table data for the n-D Lookup Table block. To propagate the change, you must register a customization function that resides on the MATLAB search path. For details, seePropagate Nonstandard Format Lookup Table Data.
This example shows how to propagate changes from the Lookup Table Editor to workspace variables of nonstandard format. Suppose your Simulink®model fromImport Nonstandard Format Lookup Table Datahas a three-dimensional lookup table that gets its table data from the two-dimensional workspace variabletable3d_map_custom
. Update the lookup table in the Lookup Table Editor and propagate these changes back totable3d_map_custom
using a customization function.
Create a file namedsl_customization.m
with these contents.
function sl_customization(cm) cm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle{end+1} = ... @myGetTableConvertInfoFcn; end
In this function:
The argumentcm
is the handle to a customization manager object.
The handle@myGetTableConvertInfoFcn
is added to the list of function handles in the cell array forcm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle
. You can use any alphanumeric name for the function whose handle you add to the cell array.
In the same file, define themyGetTableConvertInfoFcn
函数。
function blkInfo = myGetTableConvertInfoFcn(blk,tableStr) blkInfo.allowTableConvertLocal = true; blkInfo.tableWorkSpaceVarName = 'table3d_map_custom'; blkInfo.tableConvertFcnHandle = @myConvertTableFcn; end
ThemyGetTableConvertInfoFcn
function returns theblkInfo
object containing three fields.
allowTableConvertLocal
— Allows table data conversion for a block.
tableWorkSpaceVarName
— Specifies the name of the workspace variable that has a nonstandard table format.
tableConvertFcnHandle
— Specifies the handle for the conversion function.
WhenallowTableConvertLocal
is set totrue
, the table data for that block is converted to the nonstandard format of the workspace variable whose name matchestableWorkSpaceVarName
. The conversion function corresponds to the handle thattableConvertFcnHandle
specifies. You can use any alphanumeric name for the conversion function.
In the same file, define themyConvertTableFcn
函数。这个函数将一个三维al lookup table of sizeRows * Columns * Heightto a two-dimensional variable of size(Rows*Height) * Columns.
% Converts 3-dimensional lookup table from Simulink format to % nonstandard format used in workspace variable function cMap = myConvertTableFcn(data) % Determine the row and column number of the 3D table data mapDim = size(data); numCol = mapDim(2); numRow = mapDim(1)*mapDim(3); cMap = zeros(numRow, numCol); % Transform data back to a 2-dimensional matrix cMap = reshape(data,[numRow,numCol]); end
Putsl_customization.m
on the MATLAB search path. You can have multiple files namedsl_customization.m
on the search path. For more details, seeBehavior with Multiple Customization Functions.
Refresh Simulink customizations at the MATLAB command prompt.
sl_refresh_customizations
Open the Lookup Table Editor for your lookup table block and selectFile>Update Block Data. ClickYesto overwrite the workspace variabletable3d_map_custom
.
Check the value oftable3d_map_custom
in the base workspace.
table3d_map_custom = 33 2 3 4 5 6 7 8 11 12 13 14 15 16 17 18 111 112 113 114 115 116 117 118
The change in the Lookup Table Editor has propagated to the workspace variable.
If you do not overwrite the workspace variabletable3d_map_custom
, you are prompted to replace it with numeric data. ClickYesto replace the expression in theTable datafield with numeric data. ClickNoif you do not want your Lookup Table Editor changes for the table data to appear in the block dialog box.
At the start of a MATLAB session, Simulink loads eachsl_customization.m
customization file on the path and executes thesl_customization
函数。Executing each function establishes the customizations for that session.
When you selectFile>Update Block Datain the Lookup Table Editor, the editor checks the list of function handles in the cell array forcm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle
. If the cell array contains one or more function handles, theallowTableConvertLocal
property determines whether changes in the Lookup Table Editor can be propagated.
If the value is set totrue
, then the table data is converted to the nonstandard format in the workspace variable.
If the value is set tofalse
, then table data is not converted to the nonstandard format in the workspace variable.
If the value is set totrue
and another customization function specifies it to befalse
, the Lookup Table Editor reports an error.