Documentation Center

  • Trial Software
  • Product Updates

Edit Existing LookupTables

When to Use the Lookup Table Editor

Use the Lookup Table Editor to inspect and change the table elements of any lookup table block in a model, including custom blocks that you create using the Simulink® Mask Editor (see Editing Custom Lookup Table Blocks). You can also use a block parameter dialog box to edit a table. However, you must open the subsystem containing the block first and then its parameter dialog box. With the Lookup Table Editor, you can skip these steps.

    Tip   You cannot use the Lookup Table Editor to change the dimensions of a lookup table. You must use the block parameter dialog box for this purpose.

Layout of the Lookup Table Editor

To open the editor, select Lookup Table Editor from the Simulink Edit menu. The editor appears.

The editor contains two panes and a toolbar.

  • Use the left pane to browse and select lookup table blocks in any open model (see Browsing Lookup Table Blocks).

  • Use the right pane to edit the lookup table of the selected block (see Editing Table Values).

  • Use the toolbar for one-click access to frequently-used commands in the editor. Each toolbar button has a tooltip that explains its function.

Browsing Lookup Table Blocks

The Models list in the upper-left corner of the Lookup Table Editor lists the names of all models open in the current MATLAB® session. To browse lookup table blocks for any open models, select the model name from the list. A tree-structured view of lookup table blocks for the selected model appears in the Table blocks field beneath the Models list.

The tree view initially lists all lookup table blocks that reside at the model root level. It also displays any subsystems that contain lookup table blocks. Clicking the expand button (+) to the left of the subsystem name expands the tree to show lookup table blocks in that subsystem. The expanded view also shows any subsystems in the expanded subsystem. You can continue expanding subsystem nodes to display lookup table blocks at any level in the model hierarchy.

Clicking any lookup table block in the tree view displays the lookup table for that block in the right pane, so that you can edit the table (see Editing Table Values).

    Note   If you want to browse the lookup table blocks in a model that is not currently open, you can tell the Lookup Table Editor to open the model. To do this, select File > Open Model in the editor.

Editing Table Values

In the Viewing "Lookup Table (n-D)" block data table view of the Lookup Table Editor, you can edit the lookup table of the block currently selected in the adjacent tree view.

The table view displays the entire table if it is one- or two-dimensional or a two-dimensional slice of the table if the table has more than two dimensions (see Displaying N-Dimensional Tables in the Editor). To change any value that appears, double-click the value. The Lookup Table Editor replaces the value with an edit field containing the value. Edit the value and then press Enter or click outside the field to confirm the change.

In the Data Type below the table, you can specify the data type by row or column, or for the entire table. By default, the data type is double. To change the data type, select the pop-up index list for the table element for which you want to change the data type.

The Lookup Table Editor records your changes by maintaining a copy of the table. To update the copy that the lookup table block maintains, select File > Update Block Data in the Lookup Table Editor. To restore the Lookup Table Editor's copy to the values stored in the block, select File > Reload Block Data.

Working with Table Data of Standard Format

Suppose that you specify a 3-D lookup table in your n-D Lookup Table block.

You use workspace variables to define the breakpoint and table data:

The table data uses the default Simulink format:

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

The breakpoint sets have the following values:

bp3d_y =

   400  6400

bp3d_x =

     0    10    20    30

bp3d_z =

     0    10    20

When you click Edit table and breakpoints to open the Lookup Table Editor, you see:

Suppose that you change a value in the Lookup Table Editor as follows:

When you select File > Update Block Data, you can propagate the change to table3d_map, the workspace variable that contains the table data for the n-D Lookup Table block. To propagate the change, click Yes in the pop-up window that asks if you want to overwrite the workspace variable:

Working with Table Data of Nonstandard Format

Suppose that you specify a 3-D lookup table in your n-D Lookup Table block.

You use workspace variables to define the breakpoint and table data:

The table data uses a nonstandard format for representing 3-D table data that differs from the default Simulink format:

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

The expression in the Table data field converts the table data from a nonstandard format to the default Simulink format.

The breakpoint sets have the following values:

bp3d_y =

   400  6400

bp3d_x =

     0    10    20    30

bp3d_z =

     0    10    20

When you click Edit table and breakpoints to open the Lookup Table Editor, you see:

Suppose that you change a value in the Lookup Table Editor as follows:

When you select File > Update Block Data, you cannot propagate the change to table3d_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, see Example of Propagating a Change for Table Data of Nonstandard Format.

How to Propagate Changes in the Lookup Table Editor to Workspace Variables of Nonstandard Format

StepTaskReference
1Register a customization function for the Lookup Table Editor.How to Register a Customization Function for the Lookup Table Editor
2Select the appropriate responses when prompted in the Lookup Table Editor.How to Respond to Prompts in the Lookup Table Editor

How to Register a Customization Function for the Lookup Table Editor

To register a customization function for the Lookup Table Editor:

  1. In MATLAB, create a file named sl_customization.m to register your customization:

    function sl_customization(cm)
    
    cm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle{end+1} = ...
    @myConversionInfoFunction;
    
    end

    The string myConversionInfoFunction represents a function name of your choice.

  2. In your sl_customization.m file, define a function that returns a blkInfo object.

    function blkInfo = myConversionInfoFunction(blk, tableStr)
            
        blkInfo.allowTableConvertLocal = false;
        blkInfo.tableWorkSpaceVarName = '';
        blkInfo.tableConvertFcnHandle = [];
            
        % Directions for converting table data of block type 1
        if strcmp(get_param(blk, 'BlockType'), 'block_type_1')
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'variable_name_1';
        end
        
        % Directions for converting table data of block type 2
        if strcmp(get_param(blk, 'BlockType'), 'block_type_2')
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'variable_name_2';
        end
        
        ......
        
        % Directions for converting table data of block type N
        if strcmp(get_param(blk, 'BlockType'), 'block_type_N')
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'variable_name_N';
        end
    
        if blkInfo.allowTableConvertLocal
            blkInfo.tableConvertFcnHandle = @myConvertTableDataFcn;
        end
                    
    end

    For each type of lookup table block that contains nonstandard table data, specify the following three properties:

    • allowTableConvertLocal — tells the Lookup Table Editor if table data conversion is allowed 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

      Tip   You can specify more restrictive if conditions in this function. For example, to specify that table data conversion occur for a block with a given name, you can use:

      if strcmp(strrep(blk,sprintf('\n'), ' '), 'full_block_path')
          blkInfo.allowTableConvertLocal = true;
          blkInfo.tableWorkSpaceVarName = 'variable_name';
      end

    When the allowTableConvertLocal property is true:

    • The table data for that block can be converted to the nonstandard format of the workspace variable whose name matches tableWorkSpaceVarName.

    • The function that converts table data corresponds to the handle that tableConvertFcnHandle specifies.

      You can use any alphanumeric name for the conversion function. The string myConvertTableDataFcn represents a function name of your choice.

  3. In your sl_customization.m file, define the function that converts table data from the Lookup Table Editor format to the nonstandard format of your workspace variable.

  4. Verify that your sl_customization.m file is complete.

  5. Put sl_customization.m on the MATLAB search path.

      Note:   You can have multiple files with the name sl_customization.m on the search path.

  6. At the MATLAB prompt, enter the following command to refresh all Simulink customizations.

    sl_refresh_customizations

What Happens When Multiple Customization Functions Exist

If you have multiple sl_customization.m files on the search path, the following happens:

  • At the start of a MATLAB session, Simulink loads each customization file on the path and executes the function at the top. Executing each function establishes the customizations for that session.

  • When you select File > Update Block Data in the Lookup Table Editor, the editor checks the list of function handles in the cell array for cm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle.

    If the cell array...Changes in the Lookup Table Editor...

    Is empty

    Cannot propagate to workspace variables with nonstandard format

    Contains one or more function handles

    Can propagate to workspace variables with nonstandard format, depending on the value of the allowTableConvertLocal property

  • The allowTableConvertLocal property controls whether or not table data for a block is converted from the standard format in the Lookup Table Editor to a nonstandard format in a workspace variable.

    If a customization function specifies this block property to be...Then table data is...
    trueConverted to the nonstandard format in the workspace variable
    falseNot converted to the nonstandard format in the workspace variable
    true, but another customization function specifies the property to be falseNot converted and the Lookup Table Editor issues an error

How to Respond to Prompts in the Lookup Table Editor

When you select File > Update Block Data in the Lookup Table Editor, several prompts appear. Click Yes when asked if you want to:

  • Overwrite workspace variables for breakpoint data

  • Overwrite workspace variables for table data

Example of Propagating a Change for Table Data of Nonstandard Format

Suppose that you want to propagate a change from the Lookup Table Editor to the workspace variable table3d_map_custom, which uses a nonstandard format. Follow these steps:

  1. Create a file named sl_customization.m with the following contents:

    function sl_customization(cm)
    
    cm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle{end+1} = ...
    @myGetTableConvertInfoFcn;
    
    end

    In this file:

    • The sl_customization function takes a single argument cm, which is the handle to a customization manager object.

    • The handle @myGetTableConvertInfoFcn is added to the list of function handles in the cell array for cm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle.

    You can use any alphanumeric name for the function whose handle you add to the cell array. In this example, the function name is myGetTableConvertInfoFcn.

  2. In your sl_customization.m file, define the myGetTableConvertInfoFcn function.

    function blkInfo = myGetTableConvertInfoFcn(blk, tableStr)
            
        blkInfo.allowTableConvertLocal = false;
        blkInfo.tableWorkSpaceVarName = '';
        blkInfo.tableConvertFcnHandle = [];
            
        % Convert table data for n-D Lookup Table blocks
        if strcmp(get_param(blk, 'BlockType'), 'Lookup_n-D')            
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'table3d_map_custom';             
        end
            
        % Convert table data for Interpolation Using Prelookup blocks
        if strcmp(get_param(blk, 'BlockType'), 'Interpolation_n-D')
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'table4d_map_custom';
        end
            
        % Convert table data for Direct Lookup Table (n-D) blocks
        if strcmp(get_param(blk, 'BlockType'), 'LookupNDDirect')
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'table4d_map_custom';
        end
            
        if blkInfo.allowTableConvertLocal
            blkInfo.tableConvertFcnHandle = @myConvertTableFcn;
        end
                    
    end

    The myGetTableConvertInfoFcn function returns the blkInfo object, which contains three fields:

    • allowTableConvertLocal — tells the Lookup Table Editor if table data conversion is allowed 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

    When the allowTableConvertLocal property is true:

    • The table data for that block is converted to the nonstandard format of the workspace variable whose name matches tableWorkSpaceVarName.

    • The function that converts table data corresponds to the handle that tableConvertFcnHandle specifies.

      You can use any alphanumeric name for the conversion function. In this example, the function name is myConvertTableFcn.

  3. In your sl_customization.m file, define the myConvertTableFcn function, which includes a separate function call to convertTable_3D. An example of an implementation is shown below:

    % This function converts LUT block table from Simulink format to
    % nonstandard format used in workspace variable (for 1D to 4D table)
    function cMap = myConvertTableFcn(data)
            
        mapDim = size(data);
            
        numDim = length(mapDim);
            
        if numDim < 3
            cMap = data;
        elseif numDim == 3
            cMap = convertTable_3D(data);
        else % numDim == 4 , currently only supports up to 4D
            for i = 1:mapDim(numDim)
                dataSub = data(:,:,:,i);
                iStart = (i-1)*mapDim(1)*mapDim(3) + 1;
                iEnd = i*mapDim(1)*mapDim(3);
                cMap(iStart:iEnd,:) = convertTable_3D(dataSub);
            end
        end
    end
    
    % This function converts LUT block table from Simulink format to 
    % nonstandard format used in workspace variable (for 3D table) 
    function cMap = convertTable_3D(data)
            
        % figure out 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);
            
        for i = 1:mapDim(3)
            rowBegin = (i-1)*mapDim(1)+1;
            rowEnd = i*mapDim(1);
            cMap(rowBegin:rowEnd, :) = data(:,:,i);
        end
    end
  4. Verify that your sl_customization.m file is complete:

    function sl_customization(cm)
    
    cm.LookupTableEditorCustomizer.getTableConvertToCustomInfoFcnHandle{end+1} = ...
    @myGetTableConvertInfoFcn;
    
    % This function converts LUT block table from Simulink format to
    % nonstandard format used in workspace variable (for 1D to 4D table)
    function cMap = myConvertTableFcn(data)
            
        mapDim = size(data);
            
        numDim = length(mapDim);
            
        if numDim < 3
            cMap = data;
        elseif numDim == 3
            cMap = convertTable_3D(data);
        else % numDim == 4 , currently only supports up to 4D
            for i = 1:mapDim(numDim)
                dataSub = data(:,:,:,i);
                iStart = (i-1)*mapDim(1)*mapDim(3) + 1;
                iEnd = i*mapDim(1)*mapDim(3);
                cMap(iStart:iEnd,:) = convertTable_3D(dataSub);
            end
        end
    end
    
    % This function converts LUT block table from Simulink format to 
    % nonstandard format used in workspace variable (for 3D table) 
    function cMap = convertTable_3D(data)
            
        % figure out 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);
            
        for i = 1:mapDim(3)
            rowBegin = (i-1)*mapDim(1)+1;
            rowEnd = i*mapDim(1);
            cMap(rowBegin:rowEnd, :) = data(:,:,i);
        end
    end
    
    function blkInfo = myGetTableConvertInfoFcn(blk, tableStr)
            
        blkInfo.allowTableConvertLocal = false;
        blkInfo.tableWorkSpaceVarName = '';
        blkInfo.tableConvertFcnHandle = [];
            
        % Convert table data for n-D Lookup Table blocks
        if strcmp(get_param(blk, 'BlockType'), 'Lookup_n-D')            
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'table3d_map_custom';             
        end
            
        % Convert table data for Interpolation Using Prelookup blocks
        if strcmp(get_param(blk, 'BlockType'), 'Interpolation_n-D')
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'table4d_map_custom';
        end
            
        % Convert table data for Direct Lookup Table (n-D) blocks
        if strcmp(get_param(blk, 'BlockType'), 'LookupNDDirect')
            blkInfo.allowTableConvertLocal = true;
            blkInfo.tableWorkSpaceVarName = 'table4d_map_custom';
        end
            
        if blkInfo.allowTableConvertLocal
            blkInfo.tableConvertFcnHandle = @myConvertTableFcn;
        end
                    
    end
    
    end
  5. Put sl_customization.m on the MATLAB search path.

  6. At the MATLAB prompt, enter the following command to refresh all Simulink customizations.

    sl_refresh_customizations
  7. In the Lookup Table Editor, select File > Update Block Data. Several pop-up windows appear:

    1. Click Yes to overwrite the workspace variable bp3d_y.

    2. Click Yes to overwrite the workspace variable bp3d_x.

    3. Click Yes to overwrite the workspace variable table3d_map_custom.

  8. If you check the value of table3d_map_custom in the base workspace, you now see:

    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 that you make to the table data in the Lookup Table Editor propagates to the workspace variable.

    Note:   If you click No to the question of whether to overwrite the workspace variable table3d_map_custom, you get another question:

    If you click...Then...
    YesThe block dialog box replaces the expression in the Table data field with numeric data.

    NoYour Lookup Table Editor changes for the table data do not appear in the block dialog box.

Importing Data from an Excel Spreadsheet

If you have table data in a Microsoft® Excel® spreadsheet, you can import the data into the Lookup Table Editor.

How to Import Data from the Spreadsheet

To import data into the Lookup Table Editor:

  1. Save the Excel file in a folder on the MATLAB path.

  2. Open the model that contains a lookup table block.

  3. Save the model with a different name.

  4. Open the Model Properties dialog box, for example, by selecting File > Model Properties > Model Properties.

  5. Click the Callbacks tab and enter code for the model post-load function.

    For a 2-D lookup table, the commands look something like this:

    %%% BEGIN NEW CODE %%%
    % Import the data from Excel for a lookup table
    data = xlsread('name_of_spreadsheet','sheet_name');
    % Row indices for lookup table
    breakpoints1 = data(2:end,1)';
    % Column indices for lookup table
    breakpoints2 = data(1,2:end);
    % Output values for lookup table
    table_data = data(2:end,2:end);
    %%% END NEW CODE %%% 

    For more information about using xlsread, see the MATLAB documentation.

  6. Save the model again.

Example of Importing Data from an Excel Spreadsheet

Suppose that you have table data in an Excel spreadsheet named airflow_tables.xls and you want to import the data into the Lookup Table Editor.

  1. Save airflow_tables.xls in a folder on the MATLAB path. Enter the following command at the MATLAB prompt and replace destination with a location that is on the search path:

    copyfile((docpath(fullfile(docroot,'toolbox','simulink','examples','airflow_tables.xls'))),...
    'destination','f')

    For example, C:\MyFiles\airflow_tables.xls might be a valid value for destination.

  2. Open the sldemo_fuelsys model, which contains a lookup table block named Pumping Constant.

  3. Save the model with a different name, such as my_fuelsys.

  4. Open the Model Properties dialog box, for example, by selecting File > Model Properties > Model Properties.

  5. Click the Callbacks tab and add the following commands under the existing code for the post-load function:

    %%% BEGIN NEW CODE %%%
    % Import the data from Excel for a lookup table
    data = xlsread('airflow_tables', 'Pumping Constant');
    % Row indices for Pumping Constant data
    SpeedVect = data(2:end,1)';
    % Column indices for Pumping Constant data
    PressVect = data(1,2:end);
    % Output values for Pumping Constant data
    PumpCon = data(2:end,2:end);
    %%% END NEW CODE %%% 
  6. Save the model again.

Whenever you open my_fuelsys, Simulink imports the table data for the Pumping Constant block from the Excel spreadsheet.

Adding and Removing Rows and Columns in a Table

In the Lookup Table Editor, you can add and remove rows or columns of a table in the following cases:

  • Tables that are one- or two-dimensional

  • Tables defined only by breakpoints (that are inherently one-dimensional)

In those cases, follow these instructions to add or remove columns of a table in the Lookup Table Editor.

To perform this action:Use one of these methods:
Add a row or column to a table that appears in the table view
  • Select Edit > Add Row or Edit > Add Column in the editor.

  • Click the Add Row button or the Add Column button in the toolbar.

Remove a row or column from the table that appears in the table view
  • Highlight the row or column to remove and then select Edit > Remove Row(s) or Edit > Remove Column(s) in the editor.

  • Highlight the row or column to remove and then click the Remove Row button or the Remove Column button in the toolbar.

The menu items and toolbar buttons for adding and removing rows and columns are not available for any other cases. To add or remove a row or column for a table with more than two dimensions, you must use the block parameter dialog box.

Displaying N-Dimensional Tables in the Editor

If the lookup table of the block currently selected in the Lookup Table Editor's tree view has more than two dimensions, the table view displays a two-dimensional slice of the lookup table.

The Dimension Selector specifies which slice currently appears and lets you select another slice. The selector consists of a 2-by-N array of controls, where N is the number of dimensions in the lookup table. Each column corresponds to a dimension of the lookup table. The first column corresponds to the first dimension of the table, the second column to the second dimension of the table, and so on. The Dimension size row of the selector array displays the size of each dimension. The Select 2-D slice row specifies which dimensions of the table correspond to the row and column axes of the slice and the indices that select the slice from the remaining dimensions.

To select another slice of the table, specify the row and column axes of the slice in the first two columns of the Select 2-D slice row. Then select the indices of the slice from the pop-up index lists in the remaining columns.

For example, the following selector displays slice (:,:,1) of a 3-D lookup table.

To transpose the table display, select the Transpose display check box.

Plotting Lookup Tables

To display a linear or mesh plot of the table or table slice in the Lookup Table Editor, select Plot > Linear or Plot > Mesh.

Suppose that you have the following lookup table open:

A linear plot of the table looks something like this:

A mesh plot of the table looks something like this:

Editing Custom Lookup Table Blocks

You can use the Lookup Table Editor to edit custom lookup table blocks that you or others have created. To do this, you must first configure the Lookup Table Editor to recognize the custom lookup table blocks in your model. After you configure the Lookup Table Editor to recognize custom blocks, you can edit them as if they were standard blocks.

To configure the Lookup Table Editor to recognize custom blocks, select File > Configure. The Lookup Table Blocks Type Configuration dialog box appears.

By default, the dialog box displays a table of the lookup table block types that the Lookup Table Editor currently recognizes. This table includes the standard blocks. Each row of the table displays key attributes of a lookup table block type.

Adding a Custom Lookup Table Block Type

To add a custom block to the list of recognized types:

  1. Click Add on the dialog box.

    A new row appears at the bottom of the block type table.

  2. Enter information for the custom block in the new row under these headings.

    Field NameDescription

    Block type

    Block type of the custom block. The block type is the value of the block's BlockType parameter.

    Mask type

    Mask type of the custom block. The mask type is the value of the block's MaskType parameter.

    Breakpoint name

    Names of the block parameters that store the breakpoints.

    Table name

    Name of the block parameter that stores the table data.

    Number of dimensions

    Leave empty.

    Explicit dimensions

    Leave empty.

  3. Click OK.

Removing Custom Lookup Table Block Types

To remove a custom lookup table block type from the list that the Lookup Table Editor recognizes, select the custom entry in the table of the Lookup Table Blocks Type Configuration dialog box. Then click Remove.

To remove all custom lookup table block types, select the Use Simulink default lookup table blocks list check box at the top of the dialog box.

Was this topic helpful?