필터 지우기
필터 지우기

simulink random sequence generation

조회 수: 2 (최근 30일)
amin re
amin re 2013년 6월 20일
Hi,
I just created a "Malab function" block in simulink, and it generates random numbers. The problem now is that the sequence repeats whenever I run the simulation. The matlab function block simply looks like this function y=fcn() y=randn;
i know the seed should be reset but not sure how. Thanks

답변 (3개)

Kaustubha Govind
Kaustubha Govind 2013년 6월 20일
According to the documentation for randn, you need to use the function rng to control the seed, etc. You may want to look into that.

Shashank Prasanna
Shashank Prasanna 2013년 6월 20일
편집: Shashank Prasanna 2013년 6월 20일
Random numbers in all software are pseudorandom sequence of numbers. As Kaustubha already mentioned you will have to seed your random number generator differently if you don't want reproducibility (Which would be required if you want to run the simulation in the exact same way)
Include the following command at the very beginning of your matlabfunction block:
rng('shuffle')
This will choose a random seed every time.

amin re
amin re 2013년 6월 21일
편집: amin re 2013년 6월 21일
Note that I'm using a matlab function block in a simulink, that doesn't work when I use rng shuffle in the function. so basically it looks like
function y=fcn()
rng shuffle
y=rndn
however i get this error The 'shuffle' input is only supported for Mex targets with the ExtrinsicCalls option.
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2013년 6월 21일
Amin: Do you plan to generate standalone C/C++ code from your model? If not, you can call the function by declaring it extrinsic as the error suggests:
function y=fcn()
coder.extrinsic('rng');
rng('shuffle');
y=rndn;

댓글을 달려면 로그인하십시오.

카테고리

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