How do I set a seed to generate different random initial numbers and storing them
조회 수: 49 (최근 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!