How to generate non-repeatable random number in simulink in same session
조회 수: 8 (최근 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.
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!