MATLAB: Can I write to an element of a structure using the Data Store Write block during simulation using Simulink (R2009b)

simulink

I have a structure:
myStruct.a = 1;
myStruct.b = 2;
Using the Data Store Memory block, can I write to either 'a' or 'b' element of the structure in Simulink?

Best Answer

Structures inside Simulink are called Simulink Bus objects. I.e., you will have to convert the structure to a simulink.bus object. In release (MATLAB R2009b), the Data Store Memory does not support writing to Simulink Bus. And other than Data Store Write, there is no other option to write to a variable.
From MATLAB R2011a onwards we started supporting Simulink.Bus as a data type for Data Store Memory. And in the same release the 'Data Store Write' block started featuring 'Element Assignment' tab, in which you can select to write to a particular element of the Bus.
Documentation on Data Store Write (in R2012b):
You will notice, the way to access the bus elements is shown in the figures in the documentation.
Hence, any release prior to R2011a, you will not be able to write to a bus element (the equivalent of structures). Hence, it is recommended to upgrade atleast till R2011a to access these features.
For converting structures to Simulink.Bus there are methods of doing it. From R2011a onwards you can use the following command to convert a Struct to a Bus directly:
>> busInfo = Simulink.Bus.createObject( myStruct )
This creates a bus : slBus1, which has to be used inside Data Store Memory blocks as Data Type.