How do I get random numbers from a Simulink Coder executable?
이전 댓글 표시
I have a simple Simulink model that consists of a Random Number block and a To File block that writes the random number to a file. I compile this using Simulink Coder and get an executable. Every time I run the executable I get the same number. I would like to find a way to make it so that every time I run the executable I get a different number.
There was a similar problem asked here which was apparently solved, though the solution was not given. I assume that the seed is being fixed during the compilation, but I can't figure out how to change that.
If anyone has a solution I would appreciate your help. David
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2013년 2월 14일
편집: Azzi Abdelmalek
2013년 2월 14일
You create a mat file fic_seed.mat
seedv=1:300
save fic_seed seedv
In model properties-callbacks-Init Fcn write this code
v=load('fic')
v=v.v;
val=v(1);
v(1)=[];
save fic v
set_param('yoursimulinkmodelname/Random Number','seed',num2str(val))
Random Number is the name of your random block, Check if it's the same name in your simulink model.
댓글 수: 1
Kaustubha Govind
2013년 2월 14일
Azzi: Since David wants to do this in the generated code, the InitFcn callback won't help unfortunately, since it is only called within the Simulink environment.
카테고리
도움말 센터 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!