MATLAB: How to generate an output using Simulink blocks to select only the desired numbers from a number generator block in Simulink

simulink

I would like to generate a signal output from a random number generator such that:
– The numbers are plotted until the first set of zero values.
– Starting from the next non-zero value, I would like plot the data such that at the first non -zero value, I offset the output and the following values by the non-zero number.
The pseudo code that I would like to implement is as follows:
% Plot all values until first set of zeros from the random number generator
output = input;
% from the next non zero number
offset = input;
output= input-offset;

Best Answer

In the attached example, I have used a simple counter block whose outputs falls to 0 after reaching the count value 7. The subsequent values after the first zero output are offset by the first non zero value i.e 1. You may use this technique to model your system.
Related Question