How to zero order hold with time-varying sampling time?

12 views (last 30 days)
I want the sampling time to be random value that is changing during the simulation. For example from random value generator.
But i got an error, saying
The "VariableStepDiscrete" solver cannot be used to simulate block diagram 'VariableTimeSFunModel' because it contains continuous states
  1 Comment
Abdoullah NDOYE
Abdoullah NDOYE on 15 Feb 2022
Hello,
I think you have either to change the "block.SampleTimes" in the s-function and choose you own sample time or change your solver to variable step.
For me, I had a sample time of 0.2, so I put block.SampleTimes = [0.2 0];
Hope it helps !

Sign in to comment.

Answers (1)

Benjamin Thompson
Benjamin Thompson on 15 Feb 2022
Simulink blocks and sources cannot change sample times on a per sample or per update basis in the way you are describing. The solver requires predictable update time steps. However, if your simulation might be able to run at a much smaller update time than the step size you want in your input signal, you could use a Signal Builder block or a lookup table function block in Simulink to interpolate your signal onto Simulink's time base.

Community Treasure Hunt

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

Start Hunting!