Why are some of my values repeated when using the From Workspace block without interpolation in Simulink?

5 views (last 30 days)
I am using the From Workspace block to import message data from the workspace. Each time step I want a different message to be output from the block. I have created a time vector which has an entry for each time step. Occasionally, the value for a particular time step is repeated and the value for the next time step is skipped.
This only happens when I have a model with only discrete states and have cleared the Interpolate Data check box.
I have a data vector similar to the following:
data = [ ...
1;
2;
3;
4];
I generate a time vector as follows where Ts is my sample time.
Ts = 0.1;
time = (0:3)'*Ts;
However when I import this data using the from workspace block, under some circumstances, I receive the following output from that block at each time step.
1
2
2
4

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Apr 2021
Edited: MathWorks Support Team on 23 Apr 2021
This change has been incorporated into the documentation in Release 2011a (R2011a). For previous releases, read below for any additional information:
The repetition of data in the From Workspace block is an artifact of how simulation time is represented in Simulink. The simulation time is not integer based, and the calculation of the simulation time is not guaranteed to be an integer multiple of the simulation step size.
The From Workspace block compares the current simulation time with the values in the time vector. When interpolate data is not selected, it will output the data which corresponds to the last sample which is less than or equal to the current simulation time. If the current simulation time is slightly less than the expected integer multiple of the sample time, repetition can occur.
For example, if the simulation time goes from 0 to 0.1 to 0.19999999, the sample at time step 0.1 will be repeated a second time as in the example above.
If you wish to output a unique data point at each time step, it is best to not specify the sample time vector. This can be done by using the structure format of the input variable.
For example, if your input variable is to be called "var" do the following:
var.time = [];
var.signals.values = data;
var.signals.dimensions = 1;
When the time vector is empty, the following conditions must be satisfied:
1. A discrete sample time must be entered.
2. The 'Interpolate data' option cannot be selected.
3. Extrapolation can not be selected in the "Form output after final data value by:" drop down menu.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!