how to assign randomly generated numbers to a matrix say 10 by 2?
조회 수: 1 (최근 30일)
이전 댓글 표시
i have created random numbers using the code k1=randi([1,1000],1,10) Now how to assign this 10 randomly generated numbers to a matrix 10 by 2 with repetition allowed.
댓글 수: 0
채택된 답변
Walter Roberson
2015년 9월 29일
편집: Walter Roberson
2015년 9월 29일
X = randi([1,1000],10, 1);
while true
M = [X, X(randperm(length(X)))];
if all(diff(M,2)~=0); break; end
end
The while loop removes the possibility that a number is matched with itself.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!