how to assign randomly generated numbers to a matrix say 10 by 2?

조회 수: 1 (최근 30일)
chan
chan 2015년 9월 29일
댓글: chan 2015년 9월 29일
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.

채택된 답변

Walter Roberson
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by