MATLAB: How to specify an index value to the Data Store Write block without hard-coding it in R2017b

simulink

How can I specify an index value to the Data Store Write block without hard-coding it in R2017b? Is it possible to choose the Element Assignment index for a Data Store Write block using another Simulink signal value?

Best Answer

The Element Assignment expression in the Data Store Write block does not support operators, variables or functions. You can only specify a hard-coded index, such as Data(2).
You could use the Switch Case block available in Simulink > Ports & Subsystems to construct several cases for each index value with multiple Data Store Write blocks. Please find attached two models that demonstrate this workaround in different ways. Using the Switch Case block is ideal in cases where the number of indices are small. As the number of indices gets larger, this solution becomes less ideal or feasible.