how to assign randomly generated numbers to a matrix say 10 by 2?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
chan
am 29 Sep. 2015
Kommentiert: chan
am 29 Sep. 2015
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Sep. 2015
Bearbeitet: Walter Roberson
am 29 Sep. 2015
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!