Main Content

Set Execution Order Property for Block to Execute First

This example shows how to set the execution order of a Data Store Read block to execute first. The execution order specification allows the block to access the data stored in a Data Store Memory block at a previous time step of model simulation.

In the ex_dsrexecutefirst model:

  • The input data is a sine wave. At each time step, this data is amplified by a factor of two.

  • The Data Store Write block writes the amplified signal data to the Data Store Memory block.

  • The Data Store Read block reads data from the Data Store Memory block.

The default setting of the Execution Order property for the Data Store Read and Data Store Write blocks is Based on priority. This execution order setting does not allow the Data Store Read block to access the amplified sine wave value that is stored in the data store at the previous time step. To allow the Data Store Read block to access the data stored at the previous time step, configure the Data Store Read block to execute first.

Open the model.

open_system('ex_dsrexecutefirst')

To display the default execution order, in the Simulink® Editor, on the Debug tab, in the Diagnostics section, under Information Overlays, click Execution Order. On the Execution Order pane, click the recompile Circular arrow button to display the execution order.

Default execution order for blocks in the ex_dsrexecutefirst model.

Set Data Store Read Block to Execute First

To set up the Data Store Read block to execute first:

  1. Open the Block Properties dialog box. To open the dialog box, right-click the Data Store Read block, and then click the Properties button.

Properties button.

2. In the dialog box, from the Execution Order drop-down options, select First. Then, click Apply and OK.

Block Properties dialog box for the Data Store Read block.

After you change the block configuration, in the model canvas, Simulink adds the label First above the Data Store Read block.

The Data Store Read block is labeled with the word, First.

Display and Verify Updated Execution Order

Update the model (Ctrl+D) for your configuration change to take effect. You can observe the updated execution order in the Execution Order Block List. The updated list shows that the Data Store Read block executes before the Data Store Write block.

Updated execution order for blocks in the ex_dsrexecutefirst model.

See Also

| |

Topics