How do I set a seed to generate different random initial numbers and storing them
47 次查看(过去 30 天)
显示 更早的评论
for kk = 1 : Iter
xD = rand(N,1)*2*pi; % Init Cond. Driver
end
3 个评论
Wiley Mosley
2020-7-3
I think you are wanting a random repeatable setup.
I think the best way to set that up is to review:
Essentially you need to set a random repeatable seed so that you can reinitialize and run with the same random values for refining your code.
rng(1,'twister');
采纳的回答
更多回答(1 个)
Wiley Mosley
2020-7-3
编辑:Wiley Mosley
2020-7-3
rng(1,'twister'); % init generator for random repeatable with seed 1
s = rng; % save generator settings as s
for kk = 1: Iter
xD = rand (N, 1) * 2 * pi; % Init Cond. Driver
end
disp(xD) %just to print out your xD values
rng(s) % Reset the generator
for kk = 1: Iter
xD = rand (N, 1) * 2 * pi; % Init Cond. Driver
end
disp(xD) %printing out the xD values again should show that they match
I believe somthing like this should help you.
9 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!