How to generate non-repeatable random number in simulink in same session

1 次查看(过去 30 天)
I'm trying to use poissrnd to get a random distribution of numbers for determing water usage from a washer using a user defined function block in simulink. With lambda = 0.052, I get the same 'random' numbers everytime time I run the simulation. I tried using rng('shuffle') in the function block, which works but causes run-time to shoot dramatically up. I also tried simply typing rng('shuffle') into the initfunction and startfunction for the model setting, but that didn't work at all, ie same results over again.
Did some reading around of questions posted about this topic, and the closes I could find is here. How to achieve non-repeatable randomization in Stateflow? But I'm lost as to how to create the mat file, and where to save it, and how to work with the init function to call (?) the mat file to generate a random seed for each simulation run in the same session.
Can anyone provide any guidance? Thank you.

采纳的回答

Fangjun Jiang
Fangjun Jiang 2020-6-24
The MATLAB Function block is executed at every simulation step. For this case, I would suggest using rng() and poissrnd(0.52,N,1) to generate data offline and then import it into Simulink using "From Workspace" block.
  5 个评论
Ian Van Giesen
Ian Van Giesen 2020-6-25
编辑:Ian Van Giesen 2020-6-25
Great that did the trick! Btw, I ended up not using poissonrnd and rather PoissonSamp, as that got me consistently random numbers.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by