How can I make each iteration of a for each block create a unique random number?

3 次查看(过去 30 天)
I want to create a random number for all iterations of my For Each Block at each time step. I've tried by simply adding a random number in my For Each Subsystem but I get the same random number outputted for each iteration. See a test model of this below.
How can I achieve generating unique random numbers for each iteration?
One method I know exists would be to have it outside the for each loop but that is undesirable because:
  1. My model is several subsystems beneath the top level of the for each loop so it would be undesirable.
  2. I would like to create this into a library block so I don't want it to be dependent on signals at the top level.

采纳的回答

cr
cr 2022-11-28
You will have to generate a vector of random numbers outside and pass it as an input. Default partitioning of this vector might not happen the way you need it.
Cheers.
  2 个评论
Eugene Ofori
Eugene Ofori 2022-11-28
That was a solution I was hoping to avoid. I wanted to do it internal to the for each block though.
cr
cr 2022-11-28
Not sure if that is possible. The rng blocks spit a number (or a vector of numbers) in sequence for each time step. The iterations inside the foreach block are not individual time steps -just the same time step iterating over each element in the vector signal.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by