Simulink: setting different random number generator seeds even when using past SimState

18 views (last 30 days)
Hi,
I have a problem in that I need to run multiple simulations using a previously saved SimState with different randomness seeds. I haven't managed to get this to work yet.
I have tried using
set_param('mod/Random Number', 'Seed', '3324')
and this works if I don't use a previously saved SimState, but as soon as I try this with a SimState all simulations still end up with the same random numbers (I guess that the newly set seed is being ignored and instead the seed saved in the SimState is being used, although I have tried looking at the SimState data structure and I couldn't really figure out if it even contains the past seed and if it does how I am supposed to go about changing it).
What would be my best approach here?
Note: I have tried to manually implement a random generator and getting the random numbers using a root level input, but the problem here is that with a variable step solver the interpolation doesn't work!

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 14 Feb 2012
AFAIK, only tunable parameters can be changed in a simulation restored from a previously stored SimState. From what I can see, the "Seed" parameter of the Random Number block is non-tunable (you can test this by running a model containing the block for StopTime=Inf, then double-click on the block. Only textboxes corresponding to tunable-parameters are enabled during simulation).
  2 Comments
Oliver
Oliver on 14 Feb 2012
Thanks for your answer. That is what I feared. I have been able to solve the problem with a custom Random Number generator, but I think, that you should consider changing this in future generations of Matlab. Not being able to change randomness seeds means that the probabilistic nature of models is no longer reflect after using SimStates.
Thanks anyhow!
Kaustubha Govind
Kaustubha Govind on 14 Feb 2012
Oliver: Please consider submitting this as an enhancement request via MathWorks Tech Support.

Sign in to comment.

More Answers (1)

James
James on 10 Mar 2013
For those of you still looking for a solution, someone posted this on file exchange, it might help you out.

Products

Community Treasure Hunt

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

Start Hunting!