Obtaining same values at avery simulation using rand function
이전 댓글 표시
I'm building some simulations with matlab and I use rand function. I would obtain at every run, the same results. I read somewhere I have to set the seed of rand function. I tried using
s = RandStream('mcg16807', 'seed', 0)
RandStream.setGlobalStream(s);
but it didn't work.Maybe I made some mistake.
채택된 답변
추가 답변 (2개)
Azzi Abdelmalek
2012년 9월 14일
y=rand(1,100);
save file y
%when you need y
load file
Oleg Komarov
2012년 9월 14일
편집: Oleg Komarov
2012년 9월 14일
You can use rng()
rng(1)
rand(1,5)
rng(1)
rand(1,5)
Or with your approach:
s = RandStream('mcg16807', 'seed', 0);
RandStream.setGlobalStream(s);
rand(1,5)
s = RandStream('mcg16807', 'seed', 0);
RandStream.setGlobalStream(s);
rand(1,5)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!