How to put different seed in a multidimensional matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
채택된 답변
KSSV
2022년 7월 13일
n = 10; k = 3 ;
R = zeros(n,k,n) ;
for i = 1:n
rng(i) % i can be a positive integer
R(:,:,i) = rand(n,k) ;
end
댓글 수: 2
KSSV
2022년 7월 14일
Off course the number are random and they don't repeat.....also note that, there is no ncecessity to set seed for each iteration. You just need:
R = rand(10,3,10) ;
추가 답변 (2개)
Chunru
2022년 7월 13일
Not sure why you have to do this. But it can be done as follows:
n = 10; k=3;
X = zeros([n,k,n]);
seeds = [1:n]; % your seed numbers
for i=1:n
rng(seeds(i));
X(:, :, i) = rand(n, k);
end
Steven Lord
2022년 7월 13일
You might think that by changing the seed so frequently you're making the numbers "more random". You're not, as stated by the Note on this documentation page.
Call rng once before you start generating random numbers. Generate your numbers. Then if you need a different seed for your next run call rng again with a different seed.
댓글 수: 0
참고 항목
카테고리
Help Center 및 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!