Assigning certain seed value to Simulink Uniform Random Number block in programmatic way
이전 댓글 표시
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개)
카테고리
도움말 센터 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!