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.

Improve Model Readability by Eliminating Local Data Store Blocks

You can use the Model Transformer tool to improve model readability by replacing Data Store Memory, Data Store Read, and Data Store Write blocks with either a direct signal line, a Delay block, or a Merge block. For bus signals, the tool might also add Bus Creator or Bus Selector blocks as part of the replacement. Replacing these blocks improves model readability by making data dependency explicit. The Model Transformer creates a model with these replacements. The new model has the same functionality as the existing model.

The Model Transformer can replace these data stores:

  • For signals that are not buses, if a Data Store Read block executes before a Data Store Write block, the tool replaces these blocks with a Delay block.

  • For signals that are not buses, if a Data Store Write block executes before a Data Store Read block, the tool replaces these blocks with a direct connection.

  • For bus signals, if the write to bus elements executes before the read of the bus, the tool replaces the Data Store Read and Data Store Write blocks with a direct connection and a Bus Creator block.

  • For bus signals, if the write to the bus executes before the read of bus elements, the tool replaces the Data Store Read and Data Store Write blocks with a direct connection and a Bus Selector block.

  • For conditionally executed subsystems, the tool replaces the Data Store Read and Data Store Write blocks with a direct connection and a Merge block. For models in which a read/write pair crosses an If subsystem boundary and the Write block is inside the subsystem, the tool might also add an Else subsystem block.

The Model Transformer tool eliminates only local data stores that Data Store Memory blocks define. The tool does not eliminate global data stores. For the Data Store Memory block, on the Signal Attributes tab in the block parameters dialog box, you must clear the Data store name must resolve to Simulink signal object parameter.

Example Model

The model ex_data_store_elimination contains the two local data stores: B and A. For data store B, there are two Data Store Read blocks and one Data Store Write block. For data store A, there is one Data Store Write block and one Data Store Read block. The red numbers represent the sorted execution order.

Replace Data Store Blocks

Identify data store blocks that qualify for replacement. Then, create a model that replaces these blocks with direct signal lines, Delay blocks, or Merge blocks.

  1. Open the model ex_data_store_elimination. At the MATLAB® command line, enter:

    addpath(fullfile(docroot,'toolbox','simulink','examples'))
    ex_data_store_elimination

  2. Save the model to your working folder.

  3. In the Simulink Editor, from the Analysis menu, select Refactor Model > Model Transformer. To open the Model Transformer programmatically, at the MATLAB command prompt, type this command: mdltransformer('ex_data_store_replacement').

  4. In the Transformations folder, select the Eliminate data store blocks check.

  5. In the Prefix of refactored model field, specify a prefix for the refactored model.

  6. Click the Run This Check button. The top Result table contains hyperlinks to the Data Store Memory blocks and the corresponding Data Store Read and Data Store Write blocks that qualify for elimination.

  7. Click the Refactor Model button. The bottom Result table contains a hyperlink to the new model. The tool creates an m2m_ex_data_store_replacement folder. This folder contains the gen_ex_data_store_replacement.slx model.

For local data store A, gen_ex_bus_struct_in_code.slx contains a Delay block in place of the Data Store Write block and a direct signal connection in place of the Data Store Read block. For local data store B, gen_ex_bus_struct_in_code.slx contains a direct signal connection from the Bias block to Out2.

Limitations

The Model Transformer does not replace Data Store Read and Write blocks that meet these conditions:

  • They cross boundaries of conditionally executed subsystems such as Enabled, Triggered, or Function-Call subsystems and Stateflow Charts.

  • They do not complete mutually exclusive branches of If-Action subsystems.

  • They cross boundaries of variants.

  • They have more than one input or output.

  • They access part of an array.

  • They execute at different rates.

  • They are inside different instances of library subsystems and have a different relative execution order.

Related Topics