Guy on Simulink

Simulink & Model-Based Design

Data Store Enhancement: Accessing Specific Bus and Array Elements

In Simulink R2011a, Data Store blocks have been improved to support bus signals and more. To give you a quick idea, these enhancements can transform the syntax you are used to on the left to what you see on the right! This new syntax simplifies the model and the generated code. In this post I will show you some of the new capabilities that make this possible.

Advantages of the specific elements assignment feature of the Data Store in R2011a

Bus Support

Data Stores can now be used with buses! To connect a nonvirtual bus signal to a data store, all you have to do is specify the name of the bus object in the Data Type field of the Data Store Memory block:

specifying a bus object for a Data Store Memory block

Optionally, you can also specify a MATLAB structure as the bus initial value. I recommend using the function Simulink.Bus.createMATLABStruct or the Bus Editor to generate the MATLAB structure from a bus object.

Accessing specific elements of a bus or a array

Before R2011a, Data Store Write and Data Store Read blocks had only one port. With this port, you could write or read the entire memory region.

While implementing bus support, we added the option to write or read specific elements of a bus or an array. To allow this, a new Element Assignment tab has been added to the Data Store Read and Data Store Write blocks. Using this tab, you can select the components of the bus you want to write or read.

Let's look at an example. Once I have created bus object and configured the Data Store Memory block to use it, I open the dialog of a Data Store Read or Write block and select the Element Assignment tab. For this example, I decide to write the second column of element A.b.b1 and the 4th element of A.b.b2.

Configuring the Data Store Write to access only one element of a bus

Configured that way, the Data Store Write and Data Store Read have one port per assigned element, and the names of the selected elements are displayed on the blocks. Here is what a simple model looks like:

Example model illustrating how to access specific elements of DSM

Generated Code

If you generate code for the model, you will notice that this way to read and write memory is efficient, avoiding extra data copies.

Example code generated for data store

To learn more about this feature, look at the documentation titled Accessing Specific Bus and Matrix Elements. You will find out that it supports the previously existing features of buses and data store, including global data store, access from the MATLAB Function block and arrays of buses.

Now it's your turn

Did you have a need to pass bus signal through data store in the past? Are you going to take advantage of this feature? Let us know by leaving a comment here.

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.