simulink random sequence generation
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (3 件)
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.
0 件のコメント
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.
0 件のコメント
amin re
2013 年 6 月 21 日
編集済み: amin re
2013 年 6 月 21 日
1 件のコメント
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 Center および File Exchange で Sources についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!