MATLAB: Does the ‘To Workspace’ block in an Iterator block log multiple values per time point

simulink

I have created a SIMULINK model that contains a While Iterator Subsytem. I am using 'To Workspace' blocks to log the following signals:
1. The output of the 'While Iterator' block, that exists in the While Iterator Subsystem (this output is obtained by clicking the 'Show Iteration Number Port' option on the block dialog). This 'To Workspace' block is in the 'While Iterator Subsystem'.
2. The same signal as above, but the logging is done in the base model, and not within the 'While Iterator Subsystem'.
The attached 'test.mdl' model demonstrates the setup described above.
I find that the lengths of the above two data vectors (logged using the two 'To Workspace' blocks) are not equal, eventhough these blocks are logging the same signal.
In the attached 'test.mdl' model, for example, the vectors 'two' and 'four' are not of the same length.

Best Answer

This is the expected behavior. All blocks in an iterator subsystem will be executed at each iteration point, so the 'To Workspace' block will log all points, even though time is not changing.
This explains why the vectors 'two' and 'four' workspace variables are of unequal lengths, eventhough they refer to the same signal. In particular, the length of the vector 'two' is greater than the length of vector 'four'.
In order to make both these signals of the same length, the vector 'two' can be modified as shown in the code below:
two.signals.values(find(~[diff(two.time); 1]))=[];
two.time(find(~[diff(two.time); 1]))=[];
This will ensure logging of a single value per time point.
However, there is no Sink block in SIMULINK that can achieve logging of a single value per time point automatically.