Is there a block that can output a random constant and hold that value for the entire simulation in Simulink 6.2 (R14SP2)?

10 views (last 30 days)
I would like a block that outputs a constant chosen randomly and holds that value for the entire simulation. One way to do this would be to have a random constant whose sample time is inf, but I have tried using the random source blocks in the 'Sources' library and none of them allows a sample time of inf.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The ability to hold the value of a random constant for an infinite amount of time is not available in Simulink 6.2 (R14SP2). Here are three workarounds:
1. Insert a normal Constant block and set the value to be a variable, 'x' for example. Set the sample time of this block to be inf and define x randomly in the model's InitFcn callback, for example:
x = randn;
For more information on model callbacks, type the following command at the MATLAB Command Prompt:
web([docroot,'/toolbox/simulink/ug/creating_model36.html'])
2. If your simulation has a finite simulation time, then you can set the sample time of the random source block to be greater than the stop time of the simulation.
3. If you are running your simulation for an infinite amount of time and cannot use the first workaround above, then you will need to use one of the random sources in either the Signal Processing Blockset of the Communications Blockset. These sources allow sample times of inf.

More Answers (0)

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!