Assigning certain seed value to Simulink Uniform Random Number block in programmatic way
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I'm trying to directly assign seed values to multiple Simulink Uniform Random Number blocks (URN) from my .m file.
My .m file loads and configures a sweep environment of a Simulink model file.
By refering to the help center, I could assign appropriate value to Simulink Constant block by the following line:
model = 'myProject';
numIter = 4;
numNodes = 5;
constList = [1 2 3 4];
simIn(1:numIter) = Simulink.SimulationInput(model);
simulinkStopTime = 1000;
urnSeed(1) = 1;
urnSeed(2) = 102;
urnSeed(3) = 992;
urnSeed(4) = 28;
urnSeed(5) = 99;
% simulation stop time
simIn(:) = setModelParameter(simIn(:), "StopTime", num2str(simulinkStopTime))
% applying common-use variable values to Simulink
simIn(:) = setVariable(simIn(:), 'var1', var1);
simIn(:) = setVariable(simIn(:), 'var2', var2);
simIn(:) = setVariable(simIn(:), 'var3', var3);
% applying sweep variable values
for ind = 1:numIter
simIn(ind) = simIn(ind).setBlockParameter([model '/Constant1'], 'Value', num2str(constList(ind)));
end
However, I failed applying the same method to the URN blocks. The Live script output section did not show any error and I was unable to debug the project. My intention was to apply unique seed to each URN across all the sweep conditions.
for ind = 1:numNodes
simIn(:) = simIn(:).setBlockParameter([model '/Node_' ind '/EN=1 Block/Uniform Random Number'], 'See', num2str(urnSeed(ind)));
end
simulinkTic = tic;
simOut = parsim(simIn) % run parallel simulations
toc(simulinkTic)
R2023b help center says URN seed can be progmatically used with block parameter 'See.'

Is there a way to pass certain scalar values to the designated URNs from a .m file? Many thanks.
0 件のコメント
採用された回答
Paul
2023 年 9 月 25 日
Hi JW,
That looks like a typographical error in the doc (which is odd, I've always imagined stuff like that is generated automatically).
I put a URN block into a model and changed the Seed parameter to 12345. Then at the command prompt:
>> get_param(gcb,'Seed')
ans =
'12345'
>> get_param(gcb,'See')
UniformRandomNumber block does not have a parameter named 'See'
Try changing 'See' to 'Seed' in your code.
その他の回答 (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!