Read Structure From Workspace Using Model Sample Time

This example shows how to read a structure from the MATLAB workspace using a sample time specified in the From Workspace block. When you open the model, the following code is executed by a PreLoadFcn callback:

t = 0.2 * [0:49]';
x = sin(t);
y = 10*sin(t);
wave.time = [];
wave.signals.values = [x,y];
wave.signals.dimensions =2;

The From Workspace block is configured as follows:

  • Sample time: 0.2

  • Interpolate data: off

  • Form output after final data value by: Setting to zero

When you run the model, the From Workspace block reads the structure wave from the workspace. After the last time hit for which workspace data is available, the block outputs 0.