SIMULINK: Set a random seed in the Block Parameters: Random Number GUI

조회 수: 20 (최근 30일)
Marie Nancy B
Marie Nancy B 2023년 5월 27일
답변: Suman 2024년 7월 26일
SIMULINK
How do I set a random seed in the user GUI for a random number block? (So I get a random number at each sim run)
Thanks

답변 (1개)

Suman
Suman 2024년 7월 26일
Hi Marie,
You can achieve this in two very simple ways:
  1. You can set the value of the Seed parameter in the block dialog to be randi(5). This way each time the model is simulated, the seed value will be initialized to a random integer. Note that I have used the randi() function as an example, you may explore other available function as per your requirement.
  2. Another option is to use a variable in the base or model workspace as the seed value and then update its value by adding a StartFcn callback on the given block. This callback function will execute at the start of every simulation, so you again get a random value for each simulation.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by